Sound keeps playing after external swf was unloaded
I have a flash application, some kin开发者_高级运维d 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. When user switches to another video new SWF file is being loaded.
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. 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).
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.
Is there a way to solve this from the main 'loader' application?
Interestingly enough, unloadAndStop() was intended for your exact situation. 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.
One alternative solution could be to create a new instance of the Loader as opposed to using the same loader for each videos.
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... }
Try stopping all sounds before playing a new sound. Check out stopAll() call.
精彩评论