gpt4 book ai didi

flash - Flash中的流音频播放多次,重叠

转载 作者:行者123 更新时间:2023-12-03 00:20:46 26 4
gpt4 key购买 nike

以下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();
}

最佳答案

您正在play()对象上两次调用Sound。在创建变量song时一次,在完成文件加载时一次。

您可能希望以不同的方式构造代码。

var url:String = "http://md9.ca/portfolio/music/seaforth.mp3"; 

var song:SoundChannel;
var request:URLRequest = new URLRequest(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, onLoadComplete );
s.load(request);

function onLoadComplete(event:Event):void
{
song = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
s.removeEventListener( Event.COMPLETE, onLoadComplete );
}

function soundCompleteHandler(event:Event):void
{
trace( 'sound is complete' );
song.removeEventListener( Event.SOUND_COMPLETE, soundCompleteHandler );
}

我删除了 Timer代码,因为它没有任何功能。

关于flash - Flash中的流音频播放多次,重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7395568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com