All pastes #563876 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-13 10:36 UTC
rendered paste body
formatTime = function (millisecs){
	var secs = Math.floor(millisecs/1000);
	var mins = Math.floor(secs/60);
	secs %= 60;
	if (secs < 10) secs = "0"+ secs;
	if (mins < 10) mins = "0"+ mins;
	return mins +":"+ secs;	
}

var snd = this.createEmptyMovieClip("SoundController", 1);

snd.init = function(){
	snd._sound = new Sound(this);
	this.isPlaying = false;
	this.position = 0;
	loadingbar_mc._xscale = 0;
	progressbar_mc._xscale = 0;
}
snd.loadSound = function(url){
	this._sound.loadSound(url, true);
	stop_btn.onRelease();
	this.updateTime();
}
snd.updateTime = function(){
	var time = formatTime(snd.position);
	if (_root.time_mc.time_txt.text != time) _root.time_mc.time_txt.text = time;
}
snd._sound.onSoundComplete = function(){
	stop_btn.onRelease();
}
snd.onEnterFrame = function(){
	if (this._sound.getBytesLoaded() != this._sound.getBytesTotal()) {
		_root.preload._visible = 1;
		_root.time_mc._visible = 0;
	} else { _root.preload._visible = 0; _root.time_mc._visible = 1; }
	if (this.isPlaying) this.position = this._sound.position;
	this.loaded = this._sound.getBytesLoaded()/this._sound.getBytesTotal();
	loadingbar_mc._xscale = (scrubber_mc._xscale+3) * this.loaded;
	progressbar_mc._xscale = loadingbar_mc._xscale * this.position/this._sound.duration;
	this.updateTime();
}

play_btn.onRelease = function(){
	if (!isPlaying){
		snd._sound.start(snd.position/1000);	
		snd.isPlaying = true;
	}
}
pause_btn.onRelease = function(){
	if (!snd.isPlaying) return (0);
	snd.position = snd._sound.position;
	snd._sound.stop();
	snd.isPlaying = false;
}
stop_btn.onRelease = function(){
	snd.position = 0;
	snd._sound.stop();
	snd.isPlaying = false;
}
prev_btn.onRelease = function(){
	if (snd.node){
		if (snd.node.previousSibling) SetSong(snd.node.previousSibling);
		else SetSong(snd.node.parentNode.lastChild)
	}
}
next_btn.onRelease = function(){
	if (snd.node){
		if (snd.node.nextSibling) SetSong(snd.node.nextSibling);
		else SetSong(snd.node.parentNode.firstChild);
	}
}

scrubber_mc.onPress = function(){
	if (!snd.loaded) return (0);
	var pos = this._xmouse/100;
	snd.position = Math.min(snd._sound.duration, pos * snd._sound.duration/snd.loaded);
	if (snd.isPlaying) snd._sound.start(snd.position/1000);
}

SetSong = function(node){
	snd.node = node;
	snd.loadSound(node.attributes.src);
	title_txt.text = node.attributes.artist + " - " + node.attributes.title;
}

snd.init();