Search code examples
actionscript-3netstream

How do I know how much of a video is loaded by a NetStream in AS3?


I'm making a video player in AS3 and was wondering how to find out how much of the video is currently cached/buffered. I'm not sure what the correct terminology is, so I haven't been able to find it in the documentation.

NetStream.time gives me the current location of the video, so based on that I can display a progressbar.

Underneath the progressbar, I want to display how much of the video has been loaded already. How do I find this value?


Solution

  • You can use NetSteam.bytesLoaded and NetSteam.bytesTotal to get the total rough percentage loaded:

    var bufferPercent:Number = myNetStream.bytesLoaded / myNetStream.bytesTotal;
    
    // Use percentage to scale buffer bar.
    myBufferBar.scaleX = bufferPercent;