开发者

Any way to pause network traffic of NetStream class in ActionScript 3?

开发者 https://www.devze.com 2023-02-03 11:54 出处:网络
Here\'s my use case: I present a user with a set of small playing videos.When the user clicks on one of the small videos, I pause all the small ones and load a higher bitrate version of the video tha

Here's my use case:

I present a user with a set of small playing videos. When the user clicks on one of the small videos, I pause all the small ones and load a higher bitrate version of the video that was clicked.

That all works fine, except it's really slow and some network diagnostics suggest the problem is all the small videos continue to load even though I've called pause() on their netstreams.

To rephrase in code:

Suppose I have:

var nc:NetConnection = new开发者_如何学JAVA NetConnection();
nc.connect (null);   

var ns1:NetStream = new NetStream(nc);        

var vid1:Video = new Video(WIDTH, HEIGHT);
vid1.attachNetStream(ns1);
ns1.play("video1.mp4");
stage.addChild(vid1);

a few seconds go by... vid1 is still loading, and what I want to do is pause both the video stream of vid1 as well as the network traffic of loading vid1 so that the following code can run as quickly as possible

ns1.pause();

var ns2:NetStream = new NetStream(nc);
var vid2:Video = new Video(WIDTH, HEIGHT);
vid2.attachNetStream(ns2);
ns2.play("video2.mp4");
stage.addChild(vid2);

... and then some time later the user dismissed vid2, so I resume playback of vid1

ns1.resume();

Is there some way to tell ns1 to stop from reading its socket? If I call ns1.close(), then I can't resume playback with ns1.resume().

If I need to use a streaming protocol, how heavy is the handshake when loading all the small videos? I'm trying to load lots of low bitrate (50kbps) videos quickly.

Thanks!


The problem is that the movies continue to load, even though they are not playing. You can easily see that on YouTube: Just click a video and then hit pause - the progress bar continues to grow.

I believe there is no other way to stop this but to close each NetStream when it is paused. Accepting a slight delay and/or a jump to the next adjacent key frame, you can continue the movie at the last position, though: The video object the stream is assigned to should still display the last frame until there is new content, or video.clear() is called, and you can store the last playing position using ns.time and return to it after you reconnect using ns.seek ().

0

精彩评论

暂无评论...
验证码 换一张
取 消