|
-
mp3 repeating play button
I have a simple mp3 player, with PLAY PAUSE PREVIOUS and NEXT buttons.
the problem i have is if you click the play button more than once, the mp3 clip will start to play itself as many times as you clicked. this sounds really bad..u could have the clip playing over itself 5 times.
how would I say
Code:
if(play button is clicked ONCE){
(deactivate play button until next song);
}
in other words, only one PLAY-button-CLICK allowed per song...
-
you solve this on multiple ways..
for example add property var playing:Boolean
then when song starts set playing = true;
then in play button code:
if(playing){
return;
}
-
cool thanks that worked.
also, the mp3 songs just play through automatically, like one after the other. but i want them to stop at the end of each one. like i dont want it to play the next one unless the "next" button is clicked
-
Check the Event.SOUND_COMPLETE listener.
I (Love | Hate) Flash.
----
Save a version back so others may help you!
-
how would that work?
i assume somethin like
currentSong.addEventListener(Event.SOUND_COMPLETE, soundComplete);
function soundComplete(e:MouseEvent):void{
currentSong.stop();
}
but thas not gona work. there must be a wy for flash to realize when one song is finished, and then tell it to wait for ht next one
-
Total Universe Mod
There would be no need to call stop on a soundChannel that has just broadcast it's SOUND_COMPLETE event. The sound's already stopped.
The only way your songs would already be playing back to back automatically is if you responded to SOUND_COMPLETE with a call to your load sound function. Just move that call to your next buttons MOUSE_UP event.
-
no i mean i don't have a SOUND_COMPETE even in my current code, i've never used that before.
here is my full code
Code:
var my_songs:XMLList;
var my_total:Number;
var my_sound:Sound;
var my_channel:SoundChannel;
var current_song:Number=0;
var PlayinG:Boolean=false;
var song_position:Number;
var song_paused:Boolean;
guitarMOVIE.gotoAndStop(1);
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("URL HERE"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
trace(myXMLLoader);
function processXML (e:Event):void{
var myXML:XML = new XML(e.target.data);
my_songs = myXML.SONG;
my_total = my_songs.length();
myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
myXMLLoader = null;
}
function playSong(mySong:Number):void{
var myTitle = my_songs[mySong].@TITLE;
var myArtist = my_songs[mySong].@ARTIST;
var myURL = my_songs[mySong].@URL;
title_txt.text = myTitle;
artist_txt.text = myArtist;
if (my_channel){
my_channel.stop();
}
my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();
my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
}
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void{
current_song++;
if (current_song>=my_total){
current_song=0;
}
playSong(current_song);
PlayinG=true;
if(PlayinG){
return;
}
}
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void{
current_song--;
if (current_song<0){
current_song = my_total-1;
}
playSong(current_song);
PlayinG=true;
if(PlayinG){
return;
}
}
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void{
if (my_channel){
song_position = my_channel.position;
my_channel.stop();
song_paused=true;
}
}
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void{
PlayinG=true;
if (song_paused){
my_channel = my_sound.play(song_position);
song_paused=false;
} else if (!my_channel){
playSong(current_song);
}
if(PlayinG){
return;
}
}
-
Total Universe Mod
You most certainly do have a SOUND_COMPLETE listener. That's what the last line of playSong() is doing.
PHP Code:
my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
Instead of passing onNext as the handler function, pass a new one that sets the value of PlayinG to false. Then modify onNext() to only run if PlayinG is false.
There will be more fine tuning you'll want to do as you test controls while paused but that's beyond the scope of this question.
Also, at the end of onNext(), onPrev() and onPlay() you have these lines,
PHP Code:
if(PlayinG){ return;
which aren't needed since prior to those, in that same function scope, you are setting PlayinG to true so that conditional will always be true.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|