简体   繁体   English

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

[英]Sound keeps playing after external swf was unloaded

I have a flash application, some kind of a play-list that loads external SWF video player (I don't have code access to that external file), so users can watch the video or skip to another one. 我有一个Flash应用程序,某种播放列表加载外部SWF视频播放器(我没有代码访问该外部文件),因此用户可以观看视频或跳到另一个。 When user switches to another video new SWF file is being loaded. 当用户切换到另一个视频时,正在加载新的SWF文件。

The problem : If user didn't finish watching the video and skips to the next then I unload previous SWF file ( unloadAndStop() ) and load a new one. 问题 :如果用户没有看完视频并跳到下一个,那么我卸载以前的SWF文件( unloadAndStop() )并加载一个新文件。 And because the previous SWF was playing it is not actually unloaded, it is still playing on the background (I hear two audio tracks: current and previous). 而且因为以前的SWF正在播放它实际上并没有卸载,它仍然在后台播放(我听到两个音轨:当前和之前)。

I tried SoundMixer.stopAll() call, but it doesn't actually help, because of the loading on the background and and sound over the current video when it starts playing. 我尝试了SoundMixer.stopAll()调用,但它实际上并没有帮助,因为当它开始播放时背景上的加载和当前视频的声音。

Is there a way to solve this from the main 'loader' application? 有没有办法从主“加载器”应用程序解决这个问题?

Try stopping all sounds before playing a new sound. 尝试在播放新声音之前停止所有声音。 Check out stopAll() call. 看看stopAll()调用。

Interestingly enough, unloadAndStop() was intended for your exact situation. 有趣的是,unloadAndStop()适用于您的具体情况。 According to the docs... 根据文件......

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.

This seems to exactly fit your situation! 这似乎完全符合您的情况! Provided your Loader implementation is correct , this sounds like a bug in the unloadAndStop() method. 如果您的Loader实现正确,这听起来像unloadAndStop()方法中的错误。

One alternative solution could be to create a new instance of the Loader as opposed to using the same loader for each videos. 一种替代解决方案可以是创建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...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM