2014-11-04 45 views
0

我創建了一個視頻播放器到我動態地從另一個組件加載視頻如何卸載音頻:當視頻被刪除

<?xml version="1.0" encoding="utf-8"?> 
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" > 
<mx:Script> 
    <![CDATA[ 
[Bindable] public var videoAddress:String 
private static const YOUTUBE_EMBED_URL:String = "http://www.youtube.com/v/";   
[Bindable] public var videoUrl:String;         
private function init():void { 
    videoUrl = YOUTUBE_EMBED_URL+videoAddress; 
}   

    ]]> 
</mx:Script>  
<mx:SWFLoader id="swfLoader" source="{videoUrl}" width="800" height="600" /> 
</mx:Canvas> 

下面是如何加載視頻:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"> 
<mx:Script> 
    <![CDATA[ 
     private var videoPlayer:VideoPlayer; 
     protected function button1_clickHandler(event:MouseEvent):void{   
      if(this.videoPlayer != null){ 
       this.videoPlayer.removeAllChildren(); 
      } 
      videoPlayer = new VideoPlayer(); 
      videoPlayer.videoAddress = "_OBlgSz8sSM";     
      this.addChild(videoPlayer);    
     }   
     protected function button2_clickHandler(event:MouseEvent):void{   
      if(this.videoPlayer != null){ 
       this.videoPlayer.removeAllChildren(); 
      } 
      videoPlayer = new VideoPlayer(); 
      videoPlayer.videoAddress = "tvmIEP_BP9Q";     
      this.addChild(videoPlayer);    
     } 
    ]]> 
</mx:Script> 
<mx:HBox top="600"> 
    <mx:Button label="Button 1" click="button1_clickHandler(event)" />  
    <mx:Button label="Button 2" click="button2_clickHandler(event)" />  
</mx:HBox> 
</mx:Application> 

我遇到的問題是,當我加載另一個視頻時,舊視頻被刪除,新視頻加載,但舊音頻不斷播放。

如何刪除音頻?

+0

你在哪裏使用'videoUrl'var? – akmozo 2014-11-05 10:18:57

+0

videoUrl是加載到swfLoader的源代碼 – SimonRH 2014-11-05 11:19:47

回答

0

我讀了後,所討論garbage collection

對我來說,解決辦法是下面添加到init()函數: SoundMixer.stopAll();

相關問題