-
1. Re: How do I loop external audio files?
Craig Grummitt May 13, 2009 11:17 PM (in response to EntWebDS)You can loop external files by specifying the number of loops when you play the sound file. Look at the Sound.play method. eg.
var audio:Sound = new Sound(new URLRequest("http://www.pacdv.com/sounds/interface_sound_effects/sound3.mp3")); audio.play(0, 100); -
2. Re: How do I loop external audio files?
EntWebDS May 15, 2009 1:15 AM (in response to Craig Grummitt)I sincerely thank you for the helpful advice. It answers the question I asked, and I'll mark it as such, but it leaves me hanging (I think) with regard to what I wanted to ask.
I will rephrase the question and put the emphasis where I should have put it to begin with:
Is there an event that fires when an audio file finishes playing so that I can select another audio file to begin the process of loading and streaming again? The loop solution seems to fall short of accomplishing that goal since it will only loop the same file.
Also, I'm actually using a SoundChannel object, and don't know how to use the number-of-loops argument in this context. Here is the code I use:
var mysound:URLRequest = new URLRequest('../_RefFiles/bkgdmusic.mp3');
var sound:Sound = new Sound();
var controller:SoundChannel;
var play_mc:StartPlayer = new StartPlayer(); //gif image
var stop_mc:StopPlayer = new StopPlayer(); //gif image
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
//sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(mysound, context);//function soundLoaded(evt:Event):void
//{
controller = sound.play(0,200); //Doesn't work...
controller.stop();
gotoAndPlay("Play");
//}
stop();****************************
["Play" frame]
controller = sound.play();
addChild(stop_mc);
stop_mc.y=-7;
stop_mc.addEventListener(MouseEvent.CLICK, stopSound);function playSound(evt:MouseEvent):void
{
controller = sound.play();
removeChild(play_mc);
addChild(stop_mc);
stop_mc.y = -7;
stop_mc.addEventListener(MouseEvent.CLICK, stopSound);
play_mc.removeEventListener(MouseEvent.CLICK, playSound);
}function stopSound(evt:MouseEvent):void
{
controller.stop();
removeChild(stop_mc);
addChild(play_mc);
play_mc.y = -7;
play_mc.addEventListener(MouseEvent.CLICK, playSound);
stop_mc.removeEventListener(MouseEvent.CLICK, stopSound);
}
stop(); -
3. Re: How do I loop external audio files?
Craig Grummitt May 17, 2009 5:58 PM (in response to EntWebDS)In a comment in your code you say:
controller = sound.play(0,200); //Doesn't work...
however the following line you stop the sound playing:
controller.stop();
And then when you next play the sound in the 'Play' frame, you don't specify the number of loops:
controller = sound.play();
But to your question, yes looping only refers to looping the file that is playing. Playing another file after the first has stopped playing isn't really referred to as 'looping'. To check whether a sound has finished playing, you need to listen to an event on your soundChannel variable(you've called it controller) called
flash.events.Event.SOUND_COMPLETE.(SoundChannel.soundComplete). There's an example in the documentation.

