Jump to content


Photo

MP3 Player with XML - PAUSE BUTTON!


  • Please log in to reply
44 replies to this topic

#1 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 10 April 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 :D

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 :P

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.. :D

#2 travmanx

travmanx

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 11 April 2006 - 02:16 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 ;)

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 :)

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.. :o


Nice tut dude:)

#3 nodeNode

nodeNode

    Young Padawan

  • Members
  • Pip
  • 6 posts

Posted 13 April 2006 - 03:00 PM

3. then we change our play Button script slightly so we can check if pause is 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]);
	}
};

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

this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);


#4 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 13 April 2006 - 03:12 PM

nice catch! :)
Thx!

#5 nodeNode

nodeNode

    Young Padawan

  • Members
  • Pip
  • 6 posts

Posted 13 April 2006 - 03:24 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....

#6 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 13 April 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 :)

#7 jennyd52

jennyd52

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 21 April 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

#8 Amrik

Amrik

    Young Padawan

  • Members
  • Pip
  • 43 posts

Posted 09 May 2006 - 09:08 AM

Funkysoul i got a bit of prob!
i implented as said
Pause Button
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
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
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");

Edited by Amrik, 09 May 2006 - 09:15 AM.


#9 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 09 May 2006 - 11:15 AM

put on the stop button the variable
pause = false;


#10 Amrik

Amrik

    Young Padawan

  • Members
  • Pip
  • 43 posts

Posted 10 May 2006 - 12:05 AM

Thx buddy....worked perfectly alrite!!!

#11 DriveGira

DriveGira

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 10 May 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?

Edited by DriveGira, 10 May 2006 - 08:28 PM.


#12 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 11 May 2006 - 01:25 AM

put this line on top of your script, replace xx with the number of seconds you want to buffer
_soundbuftime = xx;


#13 AnTone Media

AnTone Media

    Young Padawan

  • Members
  • Pip
  • 66 posts
  • Gender:Male
  • Location:Los Angeles
  • Interests:Knowledge:<br />Photoshop, Image Ready, Dreamweaver, After Effects, Maya, Final Cut Pro, Quark Xpress<br /><br />Barely Know (Want to know more):<br />Flash/Actionscript, Audition, Premiere

Posted 03 June 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.

#14 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 03 June 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?

#15 AnTone Media

AnTone Media

    Young Padawan

  • Members
  • Pip
  • 66 posts
  • Gender:Male
  • Location:Los Angeles
  • Interests:Knowledge:<br />Photoshop, Image Ready, Dreamweaver, After Effects, Maya, Final Cut Pro, Quark Xpress<br /><br />Barely Know (Want to know more):<br />Flash/Actionscript, Audition, Premiere

Posted 03 June 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 :P lol

#16 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 03 June 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..

#17 mcRusty

mcRusty

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 22 July 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!

this.onEnterFrame = function() {
_root.title_txt._x -= 1;
if (_root.title_txt._x < (-100-_root.title_txt.width)) {
_root.title_txt._x = 219;
}
}


#18 Wowzers

Wowzers

    Young Padawan

  • Members
  • Pip
  • 40 posts

Posted 22 July 2006 - 02:49 AM

sweet. people always ask for these!

#19 funkysoul

funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 22 July 2006 - 06:34 AM

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

#20 nebula

nebula

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 31 July 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users