How to detect when video is buffering?

Posted by Leon on Stack Overflow See other posts from Stack Overflow or by Leon
Published on 2009-12-07T22:16:59Z Indexed on 2010/05/26 2:21 UTC
Read the original article Hit count: 349

Hi guys, my question today deals with Flash AS3 video buffering. (Streaming or Progressive) I want to be able to detect when the video is being buffered, so I can display some sort of animation letting the user know to wait just a little longer.

alt text

Currently my video will start up, hold on frame 1 for 3-4 secs then play. Kinda giving the impression that the video is paused or broken :(

Update

Thanks to iandisme I believe I'm faced in the right direction now. NetStatusEvent from livedocs. It seems to me that the key status to be working in is "NetStream.Buffer.Empty" so I added some code in there to see if this would trigger my animation or a trace statement. No luck yet, however when the Buffer is full it will trigger my code :/ Maybe my video is always somewhere between Buffer.Empty and Buffer.Full that's why it won't trigger any code when I test case for Buffer.Empty?

Current Code

public function netStatusHandler(event:NetStatusEvent):void 
  {
     // handles net status events
     switch (event.info.code) 

        {
            case "NetStream.Buffer.Empty":
                  trace("¤¤¤ Buffering!"); //<- never traces
                  addChild(bufferLoop);    //<- doesn't execute
            break;

            case "NetStream.Buffer.Full":
                  trace("¤¤¤ FULL!");      //<- trace works here
                  removeChild(bufferLoop); //<- so does any other code
            break;

            case "NetStream.Buffer.Flush":
                  trace("¤¤¤ FLUSH!");
                  //Not sure if this is important
            break
        }
    }

© Stack Overflow or respective owner

Related posts about flash

Related posts about actionscript-3