2011-08-23 53 views
1

我正在從外部URL加載一些MP3。 我需要等待完全加載的MP3,然後開始播放它。 你知道我該如何檢查mp3何時完全加載?當外部mp3完全加載時閃爍檢查

這是我的代碼:

var s:Sound = new Sound(new URLRequest("url.com/file.mp3")); 
var channel:SoundChannel = new SoundChannel(); 
channel = s.play(); 

最佳,弗拉維奧

回答

0

您可以監聽聲音對象的調用播放之前在完成事件。此外,由於Sound.play()返回一個SoundChannel對象,您不需要實例化一個對象,只需定義一個變量來將其引用保存在完整處理程序的範圍之外。

var channel:SoundChannel; 
var s:Sound = new Sound(new URLRequest("url.com/file.mp3")); 
s.addEventListener(Event.COMPLETE,onSoundLoaded); 

function onSoundLoaded(evt:Event):void 
{ 
    s.removeEventListener(Event.COMPLETE,onSoundLoaded); 
    channel = s.play(); 
} 
+0

Shanethehat,非常,非常適用。 –