2014-09-23 219 views
0

當pres播放它連接到流和它的一切OK! 當我點擊暫停BTN它會停止聲音,但問題 是當你點擊播放BTN後,它開始播放來自你停止它的地方的流,所有這一切都沒有發生它總是從同一地點開始流時,做第1次......刷新流內容

play_btn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound); 
pause_btn.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound); 

var fl_SC:SoundChannel = new SoundChannel; 
var fl_ToPlay:Boolean = true; 
var s:Sound = new Sound(); 
var req:URLRequest = new URLRequest("http://85.254.49.110:8002/radiov"); 
var context:SoundLoaderContext = new SoundLoaderContext(8000, true); 


function fl_ClickToPlayStopSound(evt:MouseEvent):void 
{ 
    if(fl_ToPlay) 
{ 
    s.load(req, context); 
    fl_SC = s.play(); 
    pause_btn.visible=true; 
    play_btn.visible=false; 
    spiner_mc.visible=true; 

} 
else 
{ 
    fl_SC.stop(); 
    pause_btn.visible=false; 
    play_btn.visible=true; 
    spiner_mc.visible=true; 
} 
fl_ToPlay = !fl_ToPlay; 

}

+0

我想你的代碼,並起到很好,但停藥後('fl_SC.stop() ;'),然後嘗試播放播放btn我得到了一個「錯誤:錯誤#2037:以不正確的順序調用的函數或更早的調用不成功。」 – 2014-09-23 18:58:34

+1

PS:看到這個從收音機播放「流媒體」字節的正確方法.. [[AS3 Radio Play Link](http://www.adobe.com/devnet/flashplayer/articles/icecast-streams.html)] 。如果你堅持使用聲音對象,那麼刷新你需要在播放函數中執行'new URLRequest'部分,並且還有'sound.close'來考慮。請參閱[[聲音文檔](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html)] – 2014-09-23 19:05:23

+0

找到解決方案! – user3332885 2014-09-24 09:18:05

回答

0

一切很容易!

var fl_SC:SoundChannel = new SoundChannel; 
var fl_ToPlay:Boolean = true; 

function fl_ClickToPlayStopSound(evt:MouseEvent):void 
{ 
    if(fl_ToPlay) 
{ 
    var s:Sound = new Sound(); 
    var req:URLRequest = new URLRequest("http://85.254.49.110:8002/radiov"); 
    var context:SoundLoaderContext = new SoundLoaderContext(8000, true); 
    s.load(req, context); 
    fl_SC = s.play(); 
    pause_btn.visible=true; 
    play_btn.visible=false; 

} 
else 
{ 
    fl_SC.stop(); 
    pause_btn.visible=false; 
    play_btn.visible=true; 
    } 
    fl_ToPlay = !fl_ToPlay; 
} 

在S:音響,REQ,背景和s.load不能被設置在外部,並且那一切......