actionscript-3 – 当它结束时你如何在flash AS3中循环声音?
发布时间:2020-12-15 19:47:49 所属栏目:百科 来源:网络整理
导读:AS3代码用于使用AS3循环声音? 解决方法 这不会给你完美的无间隙播放,但它会导致声音循环. var sound:Sound = new Sound();var soundChannel:SoundChannel;sound.addEventListener(Event.COMPLETE,onSoundLoadComplete);sound.load("yourmp3.mp3");// we wai
AS3代码用于使用AS3循环声音?
解决方法
这不会给你完美的无间隙播放,但它会导致声音循环.
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(); } 如果您想要通过完美无缝的无间隙播放多次循环声音,您可以拨打电话 sound.play(0,9999); // 9999 means to loop 9999 times 但是如果想在第9999次播放后想要无限播放,你仍然需要设置一个完整的声音监听器.这种做法的问题是你必须暂停/重启声音.这将创建一个soundChannel,其持续时间比实际声音文件的持续时间长9999倍,并且当持续时间长于声音长度导致可怕的崩溃时调用播放(持续时间). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |