Copy link to clipboard
Copied
hi , i have simple Start/pause/Stop Mp3 player
here is action script :
//imports the necessary as events
import flash.events.Event
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();
//Create an instance of the Sound class
var soundClip:Sound = new Sound();
//Create a new SoundChannel Object
var sndChannel:SoundChannel = new SoundChannel();
//Load sound using URLRequest
soundClip.load(new URLRequest("song.mp3"));
//Create an event listener that wll update once sound has finished loading
soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
controller.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);
function onComplete(evt:Event):void {
//Play loaded sound
sndChannel = soundClip.play();
isPlaying = true;
}
function btnPressController(evt:MouseEvent):void
{
switch(isPlaying)
{
case true:
controller.gotoAndStop(2);
pausePosition = sndChannel.position;
sndChannel.stop();
isPlaying = false;
break;
case false:
controller.gotoAndStop(1);
sndChannel = soundClip.play(pausePosition);
isPlaying = true;
break;
}
}
function btnPressStop(evt:MouseEvent):void
{
pausePosition = 0;
sndChannel.stop();
controller.gotoAndStop(2);
isPlaying = false;
}
but now i need to add Repeat Function to repeat Sound , i add this script :
soundClip.addEventListener(Event.SOUND_COMPLETE,introloop);
function introloop(e:Event):void {
sndChannel = soundClip.play(0, 9999);
isPlaying = false
}
but it now work.
any help ?? thanks ...
Also It will be Great if Help me to add more Than One sound ( maybe With Next sound bt )
Copy link to clipboard
Copied
Why do you specify isPlaying to be false i the introloop function?
You should put a trace in that function to see if the end of the sound is detected
Copy link to clipboard
Copied
thanks
i just use isPlaying = false or True for a little bit Hope and nothing chance ...
where i must Put Trace script and how this script can help me ??
Copy link to clipboard
Copied
ok i solved the repeat Problem ...
now anyone can help me about adding more Mp3 tracks and Next button please
Find more inspiration, events, and resources on the new Adobe Community
Explore Now