as3 - How to stop video and detach NetStream

与世无争的帅哥 提交于 2019-12-21 20:43:39

问题


I have video streaming from the server, and later on I want to add another one just side by side. thats all good, I done that. Now my problem comes when i want to remove video. I manage to remove it from display, but I can hear that video is still playing in the background. So how do I can stop streaming that video? Here is my code for setting up the video:

ns = new NetStream(connection);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.play(item[1].toString() + ".flv");
video = new Video();
video.attachNetStream( ns );
video.width = 160;
video.height = 120;
videoWrapper = new UIComponent();
videoWrapper.addChild( video );
videos.addElement( videoWrapper );

and here is for removing

videos.removeElement(myVideos[p][1]); // myVideos[p][1] is a reference of videoWrapper

回答1:


You can drop the connection by calling video.attachNetStream(null), or close the stream with ns.close();

It's probably best to do both.




回答2:


On a normal video object, do not call attachNetStream(null), because AS3, later will not let clear the last video frame from the video with .clear() Looks like a bug. Use ns.close(), then use vid.clear(), so that the video object can be transparent again.

On StageVideo, this is different: You can call vid.attachNetStream(null), it will remove the last frame too from the stagevideo. Be careful, it will not stop the playing itself. You have to call ns.close();



来源:https://stackoverflow.com/questions/7660754/as3-how-to-stop-video-and-detach-netstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!