0

我正在使用 OSMF 库开发视频播放器。我有一个问题,我有时会失去与服务器的连接。所以我设置了一个对象来监视与服务器的连接,如果连接丢失,它会在放弃之前尝试有限次数的重新连接。一切正常,除了我在播放器的调试器版本上收到的消息:

错误 #2044:未处理的 NetStatusEvent:。级别=错误,代码=NetStream.Play.StreamNotFound

我确实有一个从 HTTPStreamingNetLoader 继承并覆盖 processFinishLoading 方法的对象,获取 netStream 并侦听网络状态事件。像这样:

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

但我仍然得到错误。onNetStatus 方法获取诸如 NETSTREAM_BUFFER_EMPTY、NETSTREAM_BUFFER_FULL 或 NETSTREAM_PLAY_START 之类的事件,但不获取 NETSTREAM_PLAY_STREAMNOTFOUND 任何想法如何处理这个问题?谢谢。

4

3 回答 3

4

您可以从 mediaElement 获取它

mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD, onTraitAdd);

然后,

private function onTraitAdd(event:MediaElementEvent):void
{
  trace(" [add]", event.toString()); 
  if (event.traitType == MediaTraitType.LOAD)
  {

    if (mediaElement.hasTrait(MediaTraitType.LOAD))
    {
      netStreamLoadTrait = mediaElement.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
      netStreamLoadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE, onLoaded);

    }
  }
}


private function onLoaded(event:LoadEvent):void
{
  netStream = netStreamLoadTrait.netStream;
  netStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
}
于 2012-07-07T10:36:14.297 回答
2

您可以收听 MediaPlayer 状态变化:

mediaPlayer.addEventListener( MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, onMediaPlayerStateChange, false, 0, true);

...

private function onMediaPlayerStateChange(e:MediaPlayerStateChangeEvent):void
{
    _mediaState = e.state;      

    switch (_mediaState) 
    {
        case MediaPlayerState.READY:                        
        break;

        case MediaPlayerState.BUFFERING:
        break;

        case MediaPlayerState.LOADING:
        break;

        case MediaPlayerState.PAUSED:
        break;  

        case MediaPlayerState.PLAYING:
        break;  

        case MediaPlayerState.PLAYBACK_ERROR:
        break;

        case MediaPlayerState.UNINITIALIZED:
        break;
    }
}
于 2011-10-20T23:22:37.703 回答
0
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;
  }
} 
于 2011-07-12T16:42:25.273 回答