okay, yeh.. you ALWAYS wanted a pause button on your mp3 player? The time has come, here you go:
1 - First of all create a pause Button using the wingdings font and convert it to a button, don’t forget to give it an unique instance name like “btn_pause”
2 – Go to your root timeline, select your actions frame and put this after the play button… (or where-ever you want)
small explanation included bigwink.gif
1 2 3 4 5 | 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 } |
3 – Then we change our play Button script slightly so we can check if pause is true smile.gif
1 2 3 4 5 6 7 8 9 10 | 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); _root.timeDisplay_txt.text = "00:00/00:00"; this._parent.sound_mc.songStarter(songfile[song_nr]); } }; |
4. DONE!
You don’t need to use the pause variable on every situation, this was now done, because most of the people switched the random play off. Which would cause that the player wouldn’t know anymore where to start playing.



putting in your code everything worked fine other than if i pause it near the beginning it jumps a bit deeper in the song…yet if i let it play for a few seconds its ok…any ideas?
Hello, It can pause but can’t replay the position of the songs when click on play or the pause button. do you have any idea? Please reply.
Thanks
A better method is… create only one button and insert this code in frame
_root.b.onRelease = function() {
if (!pause) {
_root.mc.sb.stop();
posiP = _root.mc.sb.position/1000;
pause = true;
} else {
_root.mc.sb.start(posiP);
pause = false;
}
};
Thanks Mayank that code works beautifully
hello tiago,
thanks for the excellent tutorials. grealy appreciate them
i was just wondering what needs to be modified in the code such that the songs play in order? right now the songs play randomly, but only in order if you press rewind or fastforward.
any help would be appreciated thank you and sorry if this question was already asked and answered.
linda.
I cant for the life of me figure out why, but I cant get the song to start playing again after the pause button is pressed. When i press the play button, nothing happens.
I used the display_txt dynamic text box to check that the button was calling the function, and that pause was set to true, and that the posiP variable was passed
btn_play.onRelease = function() {if (pause == true){
this._parent.display_txt.text = posiP;
this._parent.sound_mc.sound_obj.start(posiP);
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
Im also sure that the “this._parent.sound_mc.sound_obj” is correct, because I can get the position the song was stopped in my start function.
btn_play.onRelease = function() {
if (pause == true){ // no comment....
thePosition = this._parent.sound_mc.sound_obj.position / 1000;
this._parent.display_txt.text = thePosition;
this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
}
else {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
}
However, ive just realised that if I press stop, then start 1. The playhead does not reset (please see my question in part 3 of the tutorial) and 2. if I then press pause the time/position shown when I press the play button is the additive time from when I stoped(reset) the song, and when the song restarted ie: if I pressed stop at 2 seconds, then pressed play and let it run for 2 seconds, the pressed pause, when I press play again it will show 4 seconds instead of 2. Just as important though, the song will not play
Im running macromedia flash mx (version 6). Maybe its time to upgrade?
Linda:
You just need to set random to 0
Sanfly: hmm.. looks like I missed a line of code in the tutorial.. As I mentioned before on your previous comment (part3) send me the fla file and I will have a look at it.
Regarding the upgrading to a newer flash version, definately a must
Just wanted to great tutorials,
I used your code for the pause button, but found that the stop button didn’t reset the song, also similar probs if pressing rev or fwd. I added ‘pause = false;” code under all other buttons and now it works great. Only problem, which would be awesome if you could solve, is that if a track is playing then i would like the play button to do nothing!! currently it seems to restart the track which could be annoying for users. Thanks for help! ps.
Thank you so much for these excellent tutorials. I am now creating my second website with your mp3 player and on this one I would love to have a play/pause toggle button. To this effect I have created and named 2 frames and have the text ‘STOP’ in one frame and ‘GO’ in the other. I have added the script
gotoAndPlay("goframe");to the actionscript coding for the pause button and thegotoAndPlay("pauseframe");to the play button actionscript. I have also added the actionscriptstop();to frame2 (named goframe).So far the ‘button’ works when it reads STOP ie it will pause the sound and the text will be replaced with GO but then nothing happens when I press the word GO.
Is it possible you could help me get this working or point me in a direction elsewhere on the net.
Thank you so much.
Hey Tiago! This tutorial is great! I have yet to find one as good as this one. I have to small problems that I hope are easy fixes. For the pause button, I used both your way and Mayanks way as welll and it seems to work ok at first, but as the tracks play, if I press pause it either jumps ahead in the song after I hit play from being paused, or it just jumps to the next song after I press play from being paused. Also, I inserted ‘pause = false;” at the end of the stop button, and it stops the song perfectly and then starts it from the beginning, which is exactly what I want it to do, but it displays ‘undefined’ in the text box instead of the song title. Can these 2 things be fixed? Here is my entire code on my actions layer so it may help you figure out if it is an error on my part. Thanks again.
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i0) {
delete this.onEnterFrame;
this._parent.display_txt.text = name;
} else {
this._parent.display_txt.text = “loading…”;
}
}
this.sound_obj.onSoundComplete = function (){
(song_nr==songfile.length-1)? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
}
btn_play.onRelease = function() {
if (pause == true){
this._parent.sound_mc.sound_obj.start(posiP)
}
else {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = “00:00/00:00″;
this._parent.sound_mc.songStarter(songfile[song_nr]);
}
};
btn_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
pause = false;
};
btn_fw.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_rev.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() {
this._parent.sound_mc.sound_obj.stop();
posiP = _root.sound_mc.sound_obj.position / 1000;
pause = true;
};
playlist.load(“http://www.iamtheboogeyman.com/myspace/TheShape/flash/themesongs.xml”);
Hi Tiago,
Is there a way to make it so that the pause and play button are in the same location (when the song is playing, the button shows pause.. when the song is paused or stopped, the button shows play)?
christie:
place the two buttons on the stage in the same position, make the play button on top, in ActionScript set the visibilty of the btn_play to false (on loadup):
stop();
btn_play._visible=false;
playlist= new XML();
playlist.ignoreWhite=true;
…
then in the pause button script make it visible:
btn_play._visible=true;
then in play button script make it invisible again:
btn_play._visible=false;
hi tiago
when i add play pause and stop
and when i click first play then pause and then play and then stop it functions properly afterwards i click play the song is playin from start but the timer is static on 00:00
will u see this code
btn_play.onRelease = function() {
if (pause == true){
this._parent.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
}
else {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text = “00:00″;
this._parent.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
};
btn_pause.onRelease = function() {
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = 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
}
btn_stop.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text=”00:00″;
this._parent.sound_mc.sound_obj.stop();
this._parent.sound_mc.sound_obj.position = 0;
posiP = 0;
}
Thank u very much i searched alot about that code,and this is the only site i found my answer.
Thank u again.
hi all,
I put the code in my mp3 player that is with xml, it includes 2 buttons one for the play and the other for pausing, and when it starts the first song and I click pause the song stops then i click play it starts from the position it stopped in.
When it goes to the second song I click in pause then I click on play but this time it goes to the third song and it is also in all the other songs.
so please I need help on making it stops and plays in all the songs.
Thank u all.
instead of stopping the music try to set the volume to 0 so it still keeps playing but you can’t hear it@Marty
I Can’t figure out a way to make the volume tooltip invisible when you get out of the voulme background boundaries (either left or right). Tried some conditionals within the startdrag function but no cigar
Help!?