外部swf卸载后声音继续播放

时间:2010-10-14 06:06:22

标签: flash actionscript-3 stream networkstream

我有一个Flash应用程序,某种加载外部SWF视频播放器的播放列表(我没有对该外部文件的代码访问权限),因此用户可以观看视频或跳到另一个视频。当用户切换到另一个视频时,正在加载新的SWF文件。

问题:如果用户没有看完视频并跳到下一个视频,那么我会卸载以前的SWF文件(unloadAndStop())并加载一个新文件。而且因为以前的SWF正在播放它实际上没有被卸载,它仍然在后台播放(我听到两个音轨:当前和之前)。

我尝试了SoundMixer.stopAll()来电,但实际上并没有帮助,因为当它开始播放时背景上的加载以及当前视频的声音。

有没有办法从主'loader'应用程序解决这个问题?

2 个答案:

答案 0 :(得分: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()方法中的错误。

一种替代解决方案可能是创建Loader的新实例,而不是为每个视频使用相同的加载器。

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...
}

答案 1 :(得分:0)

尝试在播放新声音之前停止所有声音。查看stopAll()来电。