2011-09-13 19 views
0

次のAS3コードでは、オーディオが複数回再生されることがあります。それは通常、そのURLで正常に動作しますが、私がhttps://soundcloud.com URLを使用すると、それはいつも狂ってしまいます。ごくまれに、ローカルファイルでも問題が発生していると思います。このコードを別の場所からコピーしたので、完全に理解できません。あなたはこの実装に問題があるのを見ていますか?まさにFlashが狂っていますか?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(); 
} 

答えて

2

あなたはSoundオブジェクトに二回play()を呼んでいます。一度変数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コードは機能しなかったため、コードを削除しました。

+0

ありがとうございました、完璧に働きます!私は、そのプレーのことが二度起こっているのを見た方がいいでしょう。 – Moss

関連する問題