ActionScript: NetStream stutters after buffering

Using NetStream to stream content from http, I noticed that esp with certain h264 exported, if a player encounters an empty buffer, it will stop and forget to the required length (as expected).

However, as soon as the buffer is full, playback does not resume, but instead jumps forward, as such, instantly reproducing the buffered duration for a short moment and, thus, again starting the empty buffer .. this will continue and more.

Presumably, when netstream pauses for buffering, the playlist position continues, and the player tries to get attached to this position when resuming, however, given that it may take 5 seconds to create a 2-second buffer, it ends up with a useless buffer again ..

(this is an assumption)

I tried to get around this by listening to the empty netstatus event of the buffer, pausing the stream and at the same time setting up a loop to check the current buffer length against the requested buffer length .. and resume after the buffer length is greater than or equal to the requested buffer. However, this causes problems when there is not enough video. For example, a 10-second buffer with the remaining 5 seconds, the loop just sits there, waiting for a buffer length of 10 seconds, when only 5 ...

You might think that you can simply check which one is smaller, the remaining time, or the requested buffer length. However, the flash response time is inaccurate.

If you add the current index of the current stream, plus buffering time, the total number will not last throughout the movie (if at the end) .. it is close, but not the same.

This brings me back to the original problem, and if there is another way to fix this, it is clear that the flash knows when the buffer is ready, so how can I get a flash pause when it is buffered and resume as soon as the buffer is ready? this is not happening at present .. it pauses and then, once the buffer is full, it plays all the buffer content after about .1 seconds.

Thanks in advance, Stephen.

+4
source share
2 answers

Well, a lot of searches around (wow, how hard it is to describe this problem). I think that additionally the problem is associated with less bandwidth, and many people cannot test this scenario.

One way or another, a lot of people experiencing this problem seem to depend on the codec settings - perhaps a keyframe or how the stream hints work. I have no idea.

What I know, this should not be a problem for the player, the flash once again becomes huge.

BUT, I managed to crack this problem, if you listen to the netstatus event and wait for an empty buffer event, you suspend the stream. Ideally, you now listen to the event with a full buffer and resume it, but since the stream is paused, the buffer is not built (but, of course, the video is still loading).

If you now set a timer (I set an event to enter the frame) and listened to one of two conditions to become true:

  • a) the buffer length is greater than or equal to bufferTime (the actual buffer at least asks for a buffer size)
  • b) the number of bytes loaded is equal to the total number of bytes

Condition A is not enough, because at the end of the video, the buffer length may not correspond to the size of the requested buffer, since the remaining time is shorter, and checking the current location of the playlist + the actual buffer length at this time is not equal to the length of the film, which is why condition B is necessary, you verify that the actual movie is fully loaded and as such is being played.

Here is my code, if at all useful to anyone:

function onNetStatus(e:NetStatusEvent):void if (e.info.code == "NetStream.Buffer.Empty") { ns.pause(); playerRoot.addEventListener(Event.ENTER_FRAME, function() { if (ns.bufferLength >= ns.bufferTime || ns.bytesLoaded == ns.bytesTotal) { playerRoot.removeEventListener(Event.ENTER_FRAME, arguments.callee); ns.resume(); } }); } } 

Greetings.

+4
source

I have never encountered the problem you described. Does this happen on every video?

One thing you can try is streaming video using JW Player to see if the same problem is happening ( http://www.longtailvideo.com/players/jw-flv-player/ ). This is an open source video player built into AS3.

0
source

All Articles