funkysoul
Apr 10 2006, 05:24 PM
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

CODE
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

CODE
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..
travmanx
Apr 11 2006, 02:16 PM
QUOTE(funkysoul @ Apr 10 2006, 10:24 PM)

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

CODE
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

CODE
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..

Nice tut dude:)
nodeNode
Apr 13 2006, 03:00 PM
3. then we change our play Button script slightly so we can check if pause is true

CODE
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]);
}
};
after implementing this bit of code I found that the song name and band don't show up after hitting stop and then play again. so i grabbed the bit from the forward button to get it working again....
CODE
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
funkysoul
Apr 13 2006, 03:12 PM
nice catch!

Thx!
nodeNode
Apr 13 2006, 03:24 PM
QUOTE(funkysoul @ Apr 13 2006, 04:11 PM)

nice catch!

Thx!
Another little bug happens when clicking pause, then play, then stop, then play... at that point, the time display stops counting time... not sure why though....
funkysoul
Apr 13 2006, 03:45 PM
strange, as soon as you press stop the counter goes back to 00, so that shouldn't be a problem of the pause button
jennyd52
Apr 21 2006, 03:15 PM
Funkysoul,
Sent you an email regarding running two versions of this MP3 player within one swf, without conflicts. Please respond, and if you think the answer might be helpful to others post the info here as well.
Thanks
Amrik
May 9 2006, 09:08 AM
Funkysoul i got a bit of prob!
i implented as said
Pause Button
CODE
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
}
then i changed paly button
CODE
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";
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
};
There r two conditions tht can happen!
Condition 1
If i play the song and press stop...the song stops...If i press play again the song will play again frm the start
Condition 2
Suppose my song is playing and suddenly i press Pause...the song will pause itself
after some time i press play again...the song will continue frm where it was paused.
Here comes the problem Now wen i want to listen to the song frm the start i press stop button...the song will stop
to listen to it again i press Play...instead of playing frm the start it plays frm where i stopped......It is like if u press pause once the stop button will start to act like pause button!!
Here is the complete code i use
CODE
stop();
playlist = new XML();
playlist.ignoreWhite=true;
playlist.onLoad = function (success) {
if(success) {
_global.songname = [];
_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;
}
}
_root.createEmptyMovieClip("sound_mc",1);
_global.song_nr = (0);
}
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;
}
MovieClip.prototype.songStarter = function (file, name) {
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.onEnterFrame = function () {
if(this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.display_txt.text=name;
timeInterval = setInterval(timer, 1000, this.sound_obj);
} else {
this._parent.display_txt.text="loading..."
}
}
this.sound_obj.onSoundComplete = function () {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text="00:00";
(song_nr==songfile.length-1)? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr],songname[song_nr]);
}
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._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();
};
}
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";
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
}
};
btn_stop.onRelease = function() {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text="00:00";
this._parent.sound_mc.sound_obj.stop();
}
btn_next.onRelease = function () {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text="00:00";
(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 () {
clearInterval(timeInterval);
this._parent.timeDisplay_txt.text="00:00";
(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");
funkysoul
May 9 2006, 11:15 AM
put on the stop button the variable
CODE
pause = false;
Amrik
May 10 2006, 12:05 AM
Thx buddy....worked perfectly alrite!!!
DriveGira
May 10 2006, 07:32 PM
Is there a way to make the player buffer up a certain amount and play once it has loaded a bit of the song? Also, Could the stop button be more like the pause button, but instead of it saving the position it just sets the position back to the begining?
funkysoul
May 11 2006, 01:25 AM
put this line on top of your script, replace xx with the number of seconds you want to buffer
CODE
_soundbuftime = xx;
AnTone Media
Jun 3 2006, 03:02 AM
funky funk soul,
you probably figured this out but when try out the player, it doesn't show the song name when it's scrolling. For certain ones, it will show but when it loads up another song, it'll scroll across and show just the line that splits the song name and band. Can you or anyone else help me with that problem.
Also, is it possible to add a scroll bar to it? It would be a great tutorial to have adding a scroll bar.
funkysoul
Jun 3 2006, 07:22 AM
if you are using ID3 tags to show up the artist & title, it will only show up when the song is completely loaded. So you need to go back to the XML version of the title or you use a FMS2 (which is $$$$) and you can use the ID3 tags...
Scrollbar? scrollbar for what? scrub the track or what?
AnTone Media
Jun 3 2006, 12:40 PM
you know after reading the last line I wrote, it made no sense to me. lol What I meant was adding a scroll bar to the playlist so that if I have tooooooooo many tracks, I can scroll through them... know what I mean, if not, then I'm a baboon at explaining things

lol
funkysoul
Jun 3 2006, 12:59 PM
what about creating a dropdown box using the components from Flash8 ?
in that way you save some space. other then that there are a bunch of tutorials out there on how to make scrollable movieclips..
mcRusty
Jul 22 2006, 02:04 AM
I fond a bug: if you export the SWF file in anything other Flash Version 6 the scrolling text just keeps going. the code thats supost to bring it back to the start point dosen't seem to be working: it's the line
if (_root.title_txt._x < (-100-_root.title_txt.width)) If I take out
-_root.title_txt.width and just had -100 it works. I been trying to figure it out for past several week and I've been pulling my hair out!
CODE
this.onEnterFrame = function() {
_root.title_txt._x -= 1;
if (_root.title_txt._x < (-100-_root.title_txt.width)) {
_root.title_txt._x = 219;
}
}
Wowzers
Jul 22 2006, 02:49 AM
sweet. people always ask for these!
funkysoul
Jul 22 2006, 06:34 AM
CODE
this.onEnterFrame = function() {
_root.title_txt._x -= 1;
if (_root.title_txt._x < (-100-_root.title_txt._width)) {
_root.title_txt._x = 219;
}
}
this should work
nebula
Jul 31 2006, 02:03 PM
Hey funkysoul,
Awesome tutorial, man. Question: Is it possible to make the textdisplayer transparent so one can only see the text and not the textfield?
Another question: Can you explain how to swap between the play and pause button during playback?
This is what I like to achieve:
When one hits play, the song will play. During playback, the pause button is being displayed instead of the playbutton at that very same place. In addittion: If stop is hit, the playbutton appears again (since there's no sound to pause)
Thx in advance,
Tijmen
funkysoul
Jul 31 2006, 04:36 PM
textdisplay transparent: disable the border and background from properties panel when you select the textfield
Swap pause and play:
CODE
btn_pause._visible = false;
btn_play.onRelease = function() {
btn_pause._visible = true;
btn_play._visible = false;
...
}
btn_pause.onRelease = function(){
btn_play._visible = true;
btn_pause._visible = false;
....
}
note that you need to enter the "visible" lines of code to the already given code.
PS: thanks for the nice comments
Wowzers
Aug 1 2006, 03:22 AM
I'm sorry I'm being lazy and Didn't feel like trying it, untill i knew for sure. But will the play button be hidden if paused and the pause hidden when playing?? lol. If not thats fine im sure i can alter it so it works like that.
funkysoul
Aug 1 2006, 04:37 AM
seems like it

btw.. dont' forget to swap the buttons around if autostart is off
Oimi
Oct 23 2006, 07:02 AM
Okay, I am stuck. I have looked through the whole of the code and compared it to the original but cannot identify why they do not behave the same. I have managed to get to Part III of the tutorial and have most of the features I want integrated. However, what I discovered was that my scrolling text only displays once, and then never appears again. Why could this be? If you could help me resolve this issue I would be very grateful. My other query is that I would like a section on my MP3 player, which drops down (like in WinAMP when you click on the down arrow button), which then displays the song/track listings with a scrollbar down the side.
Can you save me? Please?
Thank you so much for your time,
Shaun.
Oimi
Oct 23 2006, 07:15 AM
Oh yeah, here is the code I am using for the script:
stop();
title_txt.autoSize = "right";
timeDisplay_txt.autoSize = "right";
toolTip._visible = false;
var amountLoaded:Number;
var duration:Number;
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;
attachMovie("butTemp","but"+i,i+50);
eval("but"+i).id=i;
_root["but"+i]._x = 5;
_root["but"+i]._y = 40 + (i*15);
_root["but"+i].but_txt.text = songname[i];
if (i >= 3){
_root["but"+i]._x = 160
_root["but"+i]._y = -5 + (i*15);
}
_root["but"+i].onRelease = function(){
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
_root.sound_mc.songStarter(songfile[this.id]);
}
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = (0);
};
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;
}
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;
}
MovieClip.prototype.songStarter = function(file) {
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(100);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
timeInterval = setInterval(timer, 1000, this.sound_obj);
track = this.sound_obj.id3.songname;
artist = this.sound_obj.id3.artist;
this._parent.title_txt.text =artist+"/"+track;
} else {
this._parent.title_txt.text = "Song Loading";
}
};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
_root.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]);
};
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
_root.toolTip._visible = true;
setInterval(draggableTip,100);
function draggableTip(){
_root.toolTip._x = _root._xmouse;
}
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._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() {
_root.toolTip._visible = false;
stopDrag();
};
};
function soundStatus(){
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
_root.loader.loadBar._width = amountLoaded * 212.4;
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
_root.playHead._x = position / duration * 24.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
}
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]);
}
};
btn_stop.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
_root.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]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr]);
};
playlist.load("removedforanonymity(nothing wrong with the playlist)");
setInterval(duration,100);
setInterval(soundStatus,100);
Could you please also tell me how I would integrate the Play/Pause crossover using the code provided 4 posts above this one?
Thank you, Shaun.
If you want to see the player, please PM me.
LegaLega
Jan 22 2007, 11:21 AM
I am using Flash MX... and for some reason can not get the pause button to work. I attempted to debug by creating a button that has the following applicable actionscript:
TEST.onRelease = function() {
_root.sound_mc.sound_obj.stop();
_root.sound_mc.sound_obj.start(45);
};
It acts the same way. I get no sound. what am I doing wrong with the "start" code?
funkysoul
Jan 23 2007, 03:11 AM
Shouldn't it be
CODE
this._parent.sound_mc.sound_obj.start(posiP);
LegaLega
Jan 23 2007, 11:18 AM
QUOTE(funkysoul @ Jan 23 2007, 03:11 AM)

Shouldn't it be
CODE
this._parent.sound_mc.sound_obj.start(posiP);
I had it that way and it was the same result: no sound. I tried to debug by using "_root".
Here's the .fla file. I have no idea what I'm doing wrong.
Any assistance is greatly appreciated.
-James
funkysoul
Jan 23 2007, 11:36 AM
hmm funny.. I've tested out your fla file and everything is working how it should..
I'm running flash 8 pro, but I've outputted the file as a mx 2004 fla.
LegaLega
Jan 24 2007, 01:30 AM
QUOTE(funkysoul @ Jan 23 2007, 11:36 AM)

hmm funny.. I've tested out your fla file and everything is working how it should..
I'm running flash 8 pro, but I've outputted the file as a mx 2004 fla.
ahhh... i'm running flashmx.. is this the issue?
funkysoul
Jan 24 2007, 04:04 AM
actually it shouldn't be since I'm using AS 2.0..
I don't have any possibility to check it on flash mx
dlusion
Mar 4 2007, 09:33 AM
anyone managed to make a Mute button?
I made one, but doesnt work anymore if i use volumecontroller again :-/ so basicly it works for 1 time only.
Does any1 know how to make correct one?
if on release of the mute button, you should just be able to set:
CODE
if(!this.bMuted){
sound_obj.setVolume(0);
this.bMuted = true;
} else {
sound_obj.setVolume(100);
this.bMuted = false;
}
The volume slider should still work. It will need more work if you'd like it to change the location of the volume slider, or when you unmute to go to the previously selected volume.
dlusion
Mar 4 2007, 03:34 PM
thanks Pax, but it still didn't fix my problem.
With your code i end up having the same problem as before, the button won't mute anymore when i've used to volumeslider :-/
it sounds like its being overruled by something else :-/ i discovered that as soon as the volumeslider has been touched, the button doenst work anymore!
this is my code... any ideas?
CODE
stop();
var amountLoaded:Number;
var duration:Number;
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);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[
song_nr]);
};
MovieClip.prototype.songStarter = function(file, name, band) {
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
displaytags.display_txt.text = name;
displaytags.artist_txt.text = band;
} else {
displaytags.display_txt.text = "loading...";
displaytags.artist_txt.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfiles.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfiles[song_nr], songname[song_nr], songband[
song_nr]);
};
volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width - 7, this._y);
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
_root.sound_mc.sound_obj.setVolume(p);
};
}
volume1.mute.onRelease = function() {
//startDrag(this, true, 0, this._y, this._parent.volBG._width , this._y);
this.onEnterFrame = function() {
//var p = (this._x/this._parent.volBG._width)*100;
_root.sound_mc.sound_obj.setVolume(0);
};
}
volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
volume1.dragger.onReleaseOutside = function() {
stopDrag();
};
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;
}
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;
}
function soundStatus(){
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
loader.loadBar._width = amountLoaded*181;
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
playHead._x = position / duration*193-5;
}
};
mute_.onRelease = function() {
if(!this.bMuted){
_root.sound_mc.sound_obj.setVolume(0);
this.bMuted = true;
} else {
_root.sound_mc.sound_obj.setVolume(100);
this.bMuted = false;
}
}
btn_play.onRelease = function() {
clearInterval(timeInterval);
if (pause == true){ // no comment....
_root.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
}
else {
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
}
};
btn_pause.onRelease = function() { //pause button function
clearInterval(timeInterval);
_root.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
}
btn_stop.onRelease = function() {
clearInterval(timeInterval);
_root.sound_mc.sound_obj.stop();
pause = false;
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
(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]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[
song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration, 100);
setInterval(soundStatus,100);
Looks like you missed clearing an onEnterFrame. Try the following:
CODE
volume1.dragger.onReleaseOutside = function() {
stopDrag();
delete this.onEnterFrame;
};
volume1.mute.onRelease = function() {
//startDrag(this, true, 0, this._y, this._parent.volBG._width , this._y);
//this.onEnterFrame = function() {
//var p = (this._x/this._parent.volBG._width)*100;
_root.sound_mc.sound_obj.setVolume(0);
//};
}
pelicansfly
Mar 4 2007, 04:51 PM
It worked perfectly, thanks..
dlusion
Mar 5 2007, 03:31 AM
yeeeeeey! that worked for me as well!
Sorry for the misser :-)
Thanks a bunch, Pax.. really appriciate it!
dlusion
Mar 5 2007, 08:15 AM
alright.. another problem showed up...
i don't know what's wrong, but on start-up i dont hear shit but mp3 is running (proof is the secondscounter).. when i touch the volumeslider the sounds popsop outtanowhere and nothing is wrong. So basicly the sound is turned off onload.
i already tryed putting "_root.sound_mc.sound_obj.setVolume(100);" at the top of my code, but wouldnt help.
anyone who knows a solution? thanks in advance!
(it's basicly the same sourcecode from the example audioplayer3.fla, just some paths has been chanced... _root stuff)
CODE
stop();
btn_play._visible = 0;
title_txt.autoSize = "left";
timeDisplay_txt.autoSize = "left";
toolTip._visible = false;
var amountLoaded:Number;
var duration:Number;
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;
attachMovie("butTemp", "but"+i, i+50);
eval("but"+i).id = i;
_root["but"+i]._x = 5;
_root["but"+i]._y = 40+(i*15);
_root["but"+i].but_txt.text = songname[i];
if (i>=3) {
_root["but"+i]._x = 160;
_root["but"+i]._y = -5+(i*15);
}
_root["but"+i].onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
_root.sound_mc.songStarter(songfile[this.id]);
};
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr]);
};
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;
}
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;
}
MovieClip.prototype.songStarter = function(file) {
if (this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
_root.sound_mc.sound_obj = new Sound(this);
_root.sound_mc.sound_obj.loadSound(file, true);
_root.sound_mc.sound_obj.setVolume(0);
this.onEnterFrame = function() {
if (_root.sound_mc.sound_obj.position>0) {
delete this.onEnterFrame;
timeInterval = setInterval(timer, 1000, this.sound_obj);
track = this.sound_obj.id3.songname;
artist = this.sound_obj.id3.artist;
displaytags.display_txt.text = artist+" - "+track;
} else {
displaytags.display_txt.text = "loading...";
displaytags.artist_txt.text = "loading...";
}
};
_root.sound_mc.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
_root.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]);
};
volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
_root.toolTip._visible = true;
setInterval(draggableTip, 100);
function draggableTip() {
_root.toolTip._x = _root._xmouse;
}
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
_root.sound_mc.sound_obj.setVolume(p);
};
};
volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();
};
volume1.dragger.onReleaseOutside = function() {
_root.toolTip._visible = false;
stopDrag();
};
};
function soundStatus() {
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded()/_root.sound_mc.sound_obj.getBytesTotal();
loader.loadBar._width = amountLoaded*181;
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
playHead._x = position/duration*181-5;
}
mute_.onRelease = function() {
if(!bMuted){
_root.sound_mc.sound_obj.setVolume(0);
bMuted = true;
} else {
_root.sound_mc.sound_obj.setVolume(80);
bMuted = false;
}
};
btn_play.onRelease = function() {
if (pause == true) {
// no comment....
_root.sound_mc.sound_obj.start(posiP);
// start sound from the previously saved position
} else {
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
}
btn_play._visible = 0;
btn_pause._visible = 1;
};
btn_stop.onRelease = function() {
clearInterval(timeInterval);
timeDisplay_txt.text = "00:00/00:00";
_root.sound_mc.sound_obj.stop();
pause = false;
btn_play._visible = 1;
btn_pause._visible = 0;
};
btn_pause.onRelease = function() {
//pause button function
_root.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;
btn_play._visible = 1;
btn_pause._visible = 0;
//set the variable pause to true
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
_root.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]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration, 100);
setInterval(soundStatus, 100);
CODE
MovieClip.prototype.songStarter = function(file) {
if (this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
_root.sound_mc.sound_obj = new Sound(this);
_root.sound_mc.sound_obj.loadSound(file, true);
//_root.sound_mc.sound_obj.setVolume(0); This line is probably the issue
Comment out the line shown in the code above. That should fix it.
dlusion
Mar 6 2007, 06:31 AM
damn, should've seen that one..
thanks bro
Haha, dont worry about it. Its easy to miss. I develop for a living -- so in other words, I debug for a living

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.
Largo .//npc
Mar 10 2007, 06:42 PM
QUOTE(funkysoul @ May 9 2006, 04:15 PM)

put on the stop button the variable
CODE
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:
CODE
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.
Mike Truong
Jun 30 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);
ALT
Sep 11 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
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");
slimravine
Oct 26 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?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.