Flash 中的流式音频多次播放且重叠
以下 AS3 代码有时会导致音频多次播放,几乎同时播放,就像疯狂的回声一样。它通常可以正常使用该 URL,但是当我使用 https://soundcloud.com url 时,它总是会崩溃。在极少数情况下,我认为甚至本地文件也会出现此问题。我从其他地方复制了这段代码,所以我不完全理解它。您是否发现此实现有问题,还是 Flash 太疯狂了?
var url:String = "http://md9.ca/portfolio/music/seaforth.mp3";
var request:URLRequest = new URLRequest(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, completeHandler);
s.load(request); var song:SoundChannel = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
var time:Timer = new Timer(20);
time.start();
function completeHandler(event:Event):void {
event.target.play();
}
function soundCompleteHandler(event:Event):void {
time.stop();
}
The following AS3 code is sometimes causing the audio to play multiple times, almost simultaneously like a crazy echo. It usually works ok with that URL but when I use a https://soundcloud.com url it always freaks out. On rare occasions I think the issue has happened with local files even. I copied this code from somewhere else so I don't entirely understand it. Do you see a problem with this implementation or is Flash just crazy?
var url:String = "http://md9.ca/portfolio/music/seaforth.mp3";
var request:URLRequest = new URLRequest(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, completeHandler);
s.load(request); var song:SoundChannel = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
var time:Timer = new Timer(20);
time.start();
function completeHandler(event:Event):void {
event.target.play();
}
function soundCompleteHandler(event:Event):void {
time.stop();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
Sound
对象上调用play()
两次。当您创建变量song
时一次,当文件加载完成时再次一次。您可能希望以不同的方式构建代码。
我删除了 Timer 代码,因为它没有执行任何功能。
You are calling
play()
twice on theSound
object. Once when you create the variablesong
and again when the file is done loading.You might want to structure your code differently.
I removed the
Timer
code as it did not do anything functional.