如何在删除视频时卸载音频

时间:2014-11-04 23:06:36

标签: actionscript-3 flash flex flex4 flash-builder

我创建了一个视频播放器,我可以动态地从其他组件加载视频:

 <?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>

我遇到的问题是,当我加载另一个视频时,旧视频会被移除并且新视频会加载,但旧音频会继续播放。

如何删除音频?

1 个答案:

答案 0 :(得分:0)

我阅读了一篇讨论garbage collection

的帖子

我的解决方案是将以下内容添加到init()函数中: SoundMixer.stopAll();