1 Reply Latest reply on Mar 8, 2007 8:53 AM by Chris Ivey

    NetStream.Buffer.Empty doesn't fire

      When I'm buffering a Video I want to show the Clip 'bufferclip'
      The problem is that "NetStream.Buffer.Empty" doesn't seem to fire.
      I put traces in the code to see what's going on and it only returns "full"

      var nc:NetConnection = new NetConnection();
      var ns:NetStream = new NetStream(nc);
      ns.onStatus = function(info) {
      if (info.code == "NetStream.Buffer.Full") {
      bufferclip._visible = false;
      if (info.code == "NetStream.Buffer.Empty") {
      bufferclip._visible = true;
        • 1. Re: NetStream.Buffer.Empty doesn't fire
          Chris Ivey
          I've done a lot of work with the NetStream class, and will shortly be releasing a new version of my video player and captioning/events utility.

          There are two possible problems with your code. First of all, if you're declaring this block within a class, you are probably losing scope when the event actually fires. You can fix this either by using a delegate, or by attaching a handle to the video object that can be accessed regardless of scope:

          In the constructor for your videoPlayer class, you would attach a handle like this:
          _global.videoPlayer = this;

          vidStream.onStatus = function(infoObject:Object) {
          //trace("receiving video status message");
          for (var prop in infoObject) {
          //check to see if buffer has emptied and show buffer control and pause playhead
          if (infoObject[prop] == "NetStream.Buffer.Empty" && !_global.videoPlayer._videoLoaded) {
          _global.videoPlayer._bufferEmpty = true;

          This is an approach I had used; as you can see, it's a mite unhandy, so you might want to import the mx.utils.Delegate class, and then invoke a delegate when the onStatus event handler fires:

          Delegate.create(this, onBufferFull), and then declare a public onBufferFull function.

          You will notice that I am also checking the value of a variable called "videoLoaded" when handling the buffer.full empty. This is because the buffer progressively empties as you play the last few seconds of the video, (after all, there's no more video data to store in it....). You don't want your bufferclip object showing up for no apparent reason at all as the video winds down.

          The NetStream.Play.Stop event is another event you will want to capture, since you will likely want to toggle the pause/play control in your interface, and you may want to chain video clips or restart the current clip.

          Hope this helps.

          Chris Ivey