2010-10-14 56 views
3

我有一個Flash應用,某種加載外部SWF視頻播放器(我沒有代碼訪問到外部文件)一個播放列表,讓用戶可以觀看視頻或跳到另一個。當用戶切換到另一個視頻時,新的SWF文件正在加載。聲音繼續播放後,外部SWF被卸載

問題:如果用戶沒有看完視頻並跳到下一個,那麼我卸載上一個SWF文件(unloadAndStop())並加載一個新的。而且因爲之前的SWF正在播放,它實際上並未卸載,它仍在背景中播放(我聽到兩個音軌:當前和以前)。

我試過SoundMixer.stopAll()通話,但它實際上並沒有幫助,因爲在後臺加載和它開始播放時,聲音在當前的視頻。

是否有從主「裝載」的應用程序解決此問題的方法?

回答

0

有趣的是,unloadAndStop()的目的是爲您的具體情況。 按照文檔...

 
Example: A SWF file that has a music track is loaded into an application. 
Later, the SWF is unloaded using Loader.unload(). 
Though the SWF will be removed from the screen, the music will still be heard. 

SOLUTION 
Loader.unloadAndStop is a new addition to Action Script 3's API. 
It helps developers to correctly stop and unload loaded content 
using the Loader.load/loadBytes APIs. 

...Flash Player recursively attempts to stop and clear as many 
objects as possible (Sounds, NetStreams, EventListeners, etc.) 
within the loaded SWF. This feature is especially useful 
when unloading unknown 3rd party content. 

這似乎正好適合你的情況!假如你的Loader實現 是正確的,這聽起來像是在unloadAndStop()方法中的一個錯誤。

一種替代解決方案是創建裝載機的新實例,而不是使用相同的裝載機爲每個視頻。

 
private var currentMovie:DisplayObject; 

private function loadSWF(url:String):void 
{ 
    if(currentMovie != null) 
    { 
     //stop the sound playing in the current movie 
     //then remove it from the display list 
     removeChild(currentMovie); 
     currentMovie = null; 
    } 

    var loader:Loader = new Loader(); 
    //configureListeners 
    request.url = url; 
    loader.load(request , context); 

} 

private function onLoadComplete(event:Event):void 
{ 
    currentMovie = event.target.loader.content; 
    //etc... 
} 
+0

使用多個裝載機我有完全一樣的問題:如果用戶跳過50個播放視頻,他們將用50個流的播放端了。另外,如果我沒有記錯,unloadAndStop在Flash 10中引入,但外部SWF可能與'loader'不同,不知道它是否會影響函數的行爲。 – 2010-10-14 06:41:53

+0

好了,這個想法是在當前視頻被卸載後,加載器有資格進行垃圾回收,因爲這些對象不應該有任何引用。現在,如果沒有任何效果,您可以隨時檢測用戶跳到下一個視頻並停止播放當前正在播放的視頻中的聲音,但這只是一個美化補丁,它不是一個真正的解決方案 – PatrickS 2010-10-14 07:09:31

+0

我已經提到我無法訪問外部文件,如果我有我可以簡單地關閉它的網絡流。但感謝您的幫助。 – 2010-10-14 08:32:20

0

嘗試在播放新聲音之前停止所有聲音。請致電stopAll()致電。