Search code examples
flashactionscript-3osmf

How to handle NetStatusEvents with OSMF


I am developing a video player using the OSMF library. I have the problem that I sometimes lose the connection to the server. So I set up an object that watches the connection to the server and in case of connection lost it tries a limited number of times to reconnect before giving up. Everything works just fine except for the message that I get on the debugger version of the player which states:

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Play.StreamNotFound

I do have an object that inherits from HTTPStreamingNetLoader and overides the processFinishLoading method, gets the netStream and listens to the net status events. Like this:

override protected function processFinishLoading(loadTrait:NetStreamLoadTrait):void
   {    
            netStream = loadTrait.netStream as HTTPNetStream;
            netStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
    ...
    }

But I still get the error. The onNetStatus method gets events like NETSTREAM_BUFFER_EMPTY, NETSTREAM_BUFFER_FULL or NETSTREAM_PLAY_START but not NETSTREAM_PLAY_STREAMNOTFOUND Any ideas how to handle this? Thanks.


Solution

  • stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandle
    
    public function netStatusHandler(e:NetStatusEvent):void{
      switch (e.info.code){
        case "NetStream.Seek.InvalidTime":
            trace('seek was to far')
          break;
        case "NetStream.Play.StreamNotFound":
            trace("Unable to locate video");
          break;
      }
    }