使用 unloadAndStop() 方法卸载 swf,但视频声音仍然清晰可见

发布于 2024-10-17 09:10:22 字数 853 浏览 5 评论 0原文

我尝试了多种方法来卸载我的 swf,但无济于事,即使加载了 swf,我加载的 swf 中的视频声音也会继续播放。

我创建了一个通用加载器,如下所示:

var loader:Loader = new Loader();

然后我将各种 swf 加载到名为 mov_contentLoader 的影片剪辑中,例如视频 swf 加载如下:

loader.load(new URLRequest("video.swf")); //assign SWF url to loader
mov_contentLoader.addChild(loader); //add loaded content to movi clip

然后我有一个通用的“退出”按钮,基于应用程序的状态、某些窗口已关闭、swf 已卸载等。对于我的 video.swf 文件,当单击退出按钮时,我调用 unloadAndStop();加载器上的方法如下:

loader.unloadAndStop(); //unload all content, do some garbage cleanup
mov_contentLoader.removeChildAt(0); //just to be safe, a second layer of reassurance ??

SWF 已卸载,但我怎么也无法让声音停止!我什至在 video.swf 上添加舞台监听器来监听退出状态,但这仍然没有阻止视频声音。

如果我再次加载 video.swf 并播放不同的视频,则两个音轨会相互播放。

一如既往,任何指导都会受到极大的接受和赞赏。

西蒙

I have tried many approaches to unloading my swf, but to no avail, the video sounds within my laoded swf keep playing even once the swf has been loaded.

I have created a universal loader as follows:

var loader:Loader = new Loader();

I then load various swf's into a movie clip named mov_contentLoader, for example the video swf is loaded as follows:

loader.load(new URLRequest("video.swf")); //assign SWF url to loader
mov_contentLoader.addChild(loader); //add loaded content to movi clip

I then have a generic "exit" button, based on the state of the application, certain windows are closed, swf's are unloaded etc. For my video.swf file, when the exit button is clicked, I call the unloadAndStop(); method on the loader as follows:

loader.unloadAndStop(); //unload all content, do some garbage cleanup
mov_contentLoader.removeChildAt(0); //just to be safe, a second layer of reassurance ??

The SWF is unloaded, but for the life of me I can NOT get the sounds to stop! I even resorted to adding stage listeners on the video.swf to listen for an exiting state, but that still did not stop video sounds.

If I load the video.swf in again and play a different video, the two soundtracks play ontop of each other.

Any guidance, as always, is greatly accepted and appreciated.

Simon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌逼全场 2024-10-24 09:10:22

处理此问题的适当方法是将销毁函数编程到您所加载的任何内容中,然后在卸载该内容之前调用它。在销毁函数中,加载的 swf 应该负责其自己的业务:...

  • 停止播放声音。
  • 关闭所有打开的流(例如流视频)。
  • 在其时间线上调用 stop
  • 等...

SoundMixer.stopAll() 绝不是一个合适的解决方案。相反,如果您设置了“可接受”的参数,则可能是一种不和谐的用户体验,但如果您正在编写要加载到其他人的应用程序中的第 3 方 swf,那么您肯定要承担责任用于清理您自己的声音混乱,SoundMixer 不仅会杀死您的声音,还会杀死来自加载程序的声音,这肯定会激怒您的主机。

The appropriate way to handle this is to program a destroy function into whatever loaded content you have, and then call it before you unload that content. In the destroy function the loaded swf should be responsible for its own business in regards to...

  • Stopping playing sounds.
  • Closing any open streams (like streaming video).
  • calling stop on its timelines
  • etc...

SoundMixer.stopAll() is in no way an appropriate solution. Rather, it can be if you are the one setting the parameters of what is "acceptable" as a jarring user experience, but if you are writing a 3rd party swf that is to be loaded into someone else's application you'll most certainly be responsible for cleaning up your own sound mess, and SoundMixer will kill not just your sounds, but the sounds from the loader, and that is one sure fire way to anger your hosts.

‘画卷フ 2024-10-24 09:10:22

经过大量研究我已经解决了这个问题。希望这能让某人的生活变得更轻松,但问题是:

unloadAndStop(); 方法从加载的 SWF 中删除任何事件侦听器、实例、对象等。就我而言,我有视频,如果用户退出时视频仍在播放(并且加载卸载内容),声音就会继续。似乎 unloadAndStop(); 函数不做的一件事就是停止所有声音。

解决方案是什么?我将一个事件监听器附加到我的加载器,在内容成功卸载后,我调用了 SoundMixer.stopAll(); 函数,确保没有声音继续播放!然而,这确实意味着如果您一直有环境背景声音,它们也会停止。您可以更进一步,获取环境声音的当前时间,然后从该时间点立即“重新启动”它们。

我的简单发泄监听器如下所示:

myloader.contentLoaderInfo.addEventListener(Event.UNLOAD, cleanUp);

function cleanUp(e:Event):void{
   SoundMixer.stopAll(); //stop all sounds...
}

我相信这会对某人有所帮助!这有点“hacky”,但它的工作效果很好。

亲切的问候,
西蒙

After much research I have solved this problem. In the hope that this will make someone's life a lot easier, here was the issue:

The unloadAndStop(); method removes any event listeners, instances, objects etc from the loaded SWF. In my case I had videos, and IF the video was still playing when the user exited (and the loaded unloaded the content) the sounds would carry on. It seems that one thing the unloadAndStop(); function does NOT do is stop all sounds.

The solution? I attached an event listener to my loader, and after the content was successfully UNLOADED, I called the SoundMixer.stopAll(); function which ensured no sounds carried on playing! This DOES however mean that if you had ambient background sounds all along, they would stop too. You could go even further and get the current time of your ambient sounds and simply "restart" them immediately from that point in time.

My simple vent listener looks like this:

myloader.contentLoaderInfo.addEventListener(Event.UNLOAD, cleanUp);

function cleanUp(e:Event):void{
   SoundMixer.stopAll(); //stop all sounds...
}

I trust this will help someone! It's a little "hacky" but it does the job just fine.

Kind regards,
Simon

孤芳又自赏 2024-10-24 09:10:22

在您的 video.swf 中,您必须编写如下内容:

this.addEventListener(Event.REMOVED_FROM_STAGE, stopSound)

function stopSound(e:Event):void
{
    my_flvPlayer.stop();
}

In your video.swf, you have to write something like this:

this.addEventListener(Event.REMOVED_FROM_STAGE, stopSound)

function stopSound(e:Event):void
{
    my_flvPlayer.stop();
}
自此以后,行同陌路 2024-10-24 09:10:22

侦听 Event.UNLOAD 然后调用提取“SoundMixer.stopAll()”函数的函数的事件监听器是一个不错的解决方法。如果您从容器 swf 所在域之外的另一个域加载 swf,则此方法不起作用。我很确定它会触发沙箱违规。
我没有解决方案 - 无论如何,最好的解决方案是上面提到的,由 scriptocalypse 提到。

但我所处的情况是,我位于不同的域中,并且我无法控制 SWF 文件 - 因此我无法将“销毁”功能放入其中。
我要疯了。

The eventlistener that listens for the Event.UNLOAD and then calls the function which pulls out the 'SoundMixer.stopAll()' function is a decent workaround. This doesn't work if you are loading your swf from another domain than the one your container swf is on. I'm pretty sure it triggers a sandbox violation.
I do not have a solution for that - and the best solution anyway is the one mentioned above, mentioned by scriptocalypse.

But I'm in a situation where I am on different domains AND I have no control over the SWF files - so I can't put 'destroy' functions into them.
I'm going crazy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文