1

我们基于 cast.framework.events.EventType.ERROR 事件创建了一个带有通用错误侦听器的自定义 CAF 接收器:

playerManager.addEventListener(cast.framework.events.EventType.ERROR, event => { 
if (playerManager.getPlayerState() != "IDLE") {
  let errorCode = (event.detailedErrorCode != undefined ?event.detailedErrorCode : null);
  let errorMessage = null;
  if ((event.error != undefined) && (event.error.reason != null)) errorMessage = event.error.reason;

  playerManager.setIdleReason(cast.framework.messages.IdleReason.ERROR);
  customErrorCodeClass.display(errorCode, errorMessage);
});

此处理程序正常工作,但有时播放器会为单个片段引发“404 片段错误”,导致视频停止。我们无法知道该错误是否与该特定片段相关,或者是否会有其他 404 片段,因此我们无法从错误处理程序中排除该错误。

有人知道解决此问题的更好方法吗?

4

1 回答 1

0

添加以下日志,以便您知道片段会发生什么

 playerManager.addEventListener(cast.framework.events.EventType.PLAYER_LOAD_COMPLETE, () => {
        log('[mediacast:events:PLAYER_LOAD_COMPLETE');
        console.log(playerManager.getStats());
        console.log(playerManager.getMediaInformation());
    });

    playerManager.addEventListener(cast.framework.events.EventType.BITRATE_CHANGED, (event) => {
        log('[mediacast:events:BITRATE_CHANGED - ' + event.totalBitrate);
        stats.bitrate = event.totalBitrate;
        console.log(playerManager.getStats());
    });

    playerManager.addEventListener(cast.framework.events.EventType.PLAYING, (event) => {
        log('[mediacast:events:PLAYING - ', JSON.stringify(event));
    });

    playerManager.addEventListener(cast.framework.events.EventType.PAUSE, (event) => {
        log('[mediacast:events:PAUSE - ', JSON.stringify(event));
    });

    playerManager.addEventListener(cast.framework.events.EventType.SEEKING, (event) => {
        log('[mediacast:events:SEEKING - ', JSON.stringify(event));
    });

    playerManager.addEventListener(cast.framework.events.EventType.BUFFERING, (event) => {
        log('[mediacast:events:BUFFERING - ', JSON.stringify(event));
    });

    playerManager.addEventListener(cast.framework.events.EventType.TIME_UPDATE, (event) => {
        // log('[mediacast:events:TIME_UPDATE - ', JSON.stringify(event));
        stats.currentMediaTime = event.currentMediaTime;
    });

    playerManager.addEventListener(cast.framework.events.EventType.MEDIA_STATUS, (event) => {
        log('[mediacast:events:MEDIA_STATUS - ', JSON.stringify(event));
        stats.state = event.mediaStatus.playerState;
    });

并且不要忘记设置debug为记录器级别

cast.framework.CastReceiverContext.getInstance().setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
于 2019-05-20T10:39:27.547 回答