Jump to content


Photo

MP3 Player with XML - PAUSE BUTTON!


  • Please log in to reply
44 replies to this topic

#41 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 06 March 2007 - 09:19 AM

Haha, dont worry about it. Its easy to miss. I develop for a living -- so in other words, I debug for a living :rolleyes: You learn what to look for, and you learn that you can spend hours debugging, only to find in the end it was that one line of code at the very bottom of the most inconsequential class that you accidentally commented out, or you forgot an = sign in an if statement. So many things are so small and hard to miss. One thing you should use tho, is the search function in flash. In the previous problem, if you knew your volume was being set low, you can search the document for the code that would do that. So you would search for: "setVolume". Not setVolume(0);, because even if it were setVolume(3); you probably couldnt hear it, but your search wouldnt find it.

Glad you got things working.

#42 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 10 March 2007 - 06:42 PM

put on the stop button the variable

pause = false;


That didn't quite do the trick for me, but I added the following, which fixed the pause problem.

Replace the play btn code with this:
btn_play.onRelease = function() {
	if (pause == true) {
		this._parent.sound_mc.sound_obj.start(posiP);
		pause = false;
	} else {
		clearInterval(timeInterval);
		this._parent.timeDisplay_txt.text = "00:00";
		this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
	}
};

It's just added the pause = false var if play is pressed after being paused. Clicking Next play while playing no longer takes you back to the pause position.
Love your code, best MP3 player for flash I've seen and used/tweaked.

#43 Mike Truong

Mike Truong

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 30 June 2007 - 05:12 PM

Hello,

I added a pause button. It can pause but can’t replay the position of the songs when click on play button. Is it something wrong with the code? Please help....


My code:





stop();
title_txt.autoSize = "left";
timeDisplay_txt.autoSize = "left";

playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
//trace(songname[i]+" "+songfile[i]+" "+songband[i]);
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = (0);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
};

// Timer Duration
function duration () {
timed = _root.sound_mc.sound_obj.duration/1000;
mind = Math.floor(timed/60);
mind = (mind<10) ? "0"+mind : mind;
secd = Math.floor(timed%60);
secd = (secd<10) ? "0"+secd : secd;
totalDuration = mind+":"+secd;
};

// Sound Timer
function timer(sound_obj) {
time = sound_obj.position/1000;
min = Math.floor(time/60);
min = (min<10) ? "0"+min : min;
sec = Math.floor(time%60);
sec = (sec<10) ? "0"+sec : sec;
timeDisplay_txt.text = min+":"+sec+"/"+totalDuration;
};

// Song Starter
MovieClip.prototype.songStarter = function(file, name, band) {
if(this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.sound_obj.setVolume(0);
//trace(CurrentVolume);
this._parent.equalizer.gotoAndStop("eqstart");


// Text Title
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.title_txt.text = name+" - "+band;
timeInterval = setInterval(timer, 1000, this.sound_obj);
} else {
this._parent.title_txt.text = "loading song...";
}
};

// Loading Sound Function
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
this._parent.equalizer.gotoAndStop("eqstop");
};

// Volume Dragger
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.dragger_bar._width, this._y);
this.onEnterFrame = function() {
var p = (this._x/this._parent.dragger_bar._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume(p);
};
};
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
this._parent.volume1.dragger.onReleaseOutside = function() {
stopDrag();
};
};

// Stop button Function
btn_stop.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.sound_obj.stop();
this._parent.equalizer.gotoAndStop("eqstop");
};

// Pause button Function
btn_pause.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
pausetime = this._parent.sound_mc.sound_obj.position/1000;
paused = true;
this._parent.equalizer.gotoAndStop("eqstop");
};

// Play button Function
btn_play.onRelease = function() {
if(paused==true) {
this._parent.sound_mc.sound_obj.songStarter(pausetime);
} else {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
this._parent.equalizer.gotoAndStop("eqstart");
}
};

playlist.load("playlist.xml");
setInterval(duration,100);

#44 ALT

ALT

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 11 September 2008 - 10:58 PM

ok ive done part one adn now im trying to add the puase buton and i did as u said and i cant get it to work it dosnt do anything when i click puase
(im using cs3 with actionscript2)
her is my code
stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
	if (success) {
		_global.songname = [];
		_global.songband = [];
		_global.songfile = [];
		for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
			_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
			_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
			trace(songname[i]+"  "+songfile[i]);
		}
	}
	_root.createEmptyMovieClip("sound_mc", 1);
	_root.sound_mc.sound_obj = new Sound();
	_global.song_nr = random(songfile.length);
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
MovieClip.prototype.songStarter = function(file, name) {
	this.sound_obj.loadSound(file, true);
	this.onEnterFrame = function() {
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			this._parent.display_txt.text = name;
		} else {
			this._parent.display_txt.text = "loading...";
		}
	};
	this.sound_obj.onSoundComplete = function() {
		(song_nr == songfiles.length-1) ? _global.song_nr=0 : _global.song_nr++;
		_root.sound_mc.songStarter(songfiles[song_nr], songname[song_nr]);
	};
};
btn_play.onRelease = function() {
	if (pause == true){ // no comment....
				this._parent.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
	}
	else {
	clearInterval(timeInterval);
		this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
	}
};
btn_stop.onRelease = function() {
	this._parent.sound_mc.sound_obj.stop();
};
btn_next.onRelease = function() {
	(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
btn_prev.onRelease = function() {
	(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
btn_pause.onRelease = function() { //pause button function
	this._parent.sound_mc.sound_obj.stop(); //stop the current sound
	posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
	pause = true;//set the variable pause to true
};
playlist.load("playlist.xml");


#45 slimravine

slimravine

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 26 October 2008 - 01:01 PM

absolutely brilliant player my friend. I can't thank you enough for all your efforts with your tutorials. I have a simple question I hope somebody can help me with: How can I have the player load without playing the 1st song until the user presses play?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users