scr*_*pse 27
这不会给你完美的无间隙播放,但它会导致声音循环.
var sound:Sound = new Sound();
var soundChannel:SoundChannel;
sound.addEventListener(Event.COMPLETE, onSoundLoadComplete);
sound.load("yourmp3.mp3");
// we wait until the sound finishes loading and then play it, storing the
// soundchannel so that we can hear when it "completes".
function onSoundLoadComplete(e:Event):void{
sound.removeEventListener(Event.COMPLETE, onSoundLoadComplete);
soundChannel = sound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
}
// this is called when the sound channel completes.
function onSoundChannelSoundComplete(e:Event):void{
e.currentTarget.removeEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
soundChannel = sound.play();
}
Run Code Online (Sandbox Code Playgroud)
如果您想要通过完美无缝的无间隙播放多次循环声音,您可以拨打电话
sound.play(0, 9999); // 9999 means to loop 9999 times
Run Code Online (Sandbox Code Playgroud)
但是如果你想在第9999次播放后想要无限播放,你仍然需要设置一个完整的声音监听器.这种做事方式的问题是你必须暂停/重启声音.这将创建一个soundChannel,其持续时间比实际声音文件的持续时间长9999倍,并且当持续时间长于声音长度导致可怕的崩溃时调用播放(持续时间).
fra*_*mes 10
var sound:Sound = whateverSoundYouNeedToPlay;
function playSound():void
{
var channel:SoundChannel = sound.play();
channel.addEventListener(Event.SOUND_COMPLETE, onComplete);
}
function onComplete(event:Event):void
{
SoundChannel(event.target).removeEventListener(event.type, onComplete);
playSound();
}
Run Code Online (Sandbox Code Playgroud)