views:

106

answers:

1

I'm trying to accurately determine how many seconds of a video (NetStream) have been loaded so I can scrub/seek correctly. First I tried doing duration*(ns.bytesLoaded/ns.bytesTotal) but this is inaccurate by maybe 15%, ie if that calculation says 20 seconds is loaded and I scrub to 20 seconds ns.time will tell me it can't go past 17 seconds.

I think this is because the size of the file loaded doesn't map perfectly to the number of seconds loaded (obviously), ie as the video loads, some of the bytes loaded aren't the actual video but are overhead of the container/file the video is in. So to load 1% of video you have to actually load 1.15% of the file's size.

Anybody know a work around to determine seconds loaded?

A: 

bufferLength indicates the number of seconds currently in the buffer. You can use this with time to determine how much in total has been loaded.

Anon.
I saw bufferLength and hoped it was the solution but for some reason ns.bufferLength is always 0. I'm not sure if thats because this is playing from a file (as opposed to live streaming) or because its a h264 .mp4 and not a .flv.
Shizam