1

我正在尝试在 chromecast 上播放多语言音轨。它播放视频/音频文件,但不会从英语切换到西班牙语。我可以在 silverlight 播放器中使用相同的文件进行切换。我已将我的 chromecast 播放器语言和我的 android 手机语言设置为西班牙语。在 Google Cast SDK Developer 控制台中,我添加了西班牙语作为备用曲目。

我已经使用谷歌指南中指定的代码添加了我的自定义播放器,但是指南中的代码似乎无法直接复制和粘贴。有人可以指导我为什么 protocol.getStreamCount() 为 0 吗?通话时间是否正确?这是我正在使用的整个播放器,请特别注意 window.changeLanguage = function()... 和 changeLanguage 调用。非常感谢任何帮助!

<html>
<head>
  <title>Test Player</title>
  <script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
  <script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/mediaplayer/1.0.0/media_player.js"></script>
  <link rel="stylesheet" type="text/css" href="chromecast.css" />
</head>
<body>
<video id='vid' />


<script type="text/javascript">
if (window.location.href.indexOf('Debug=true') != -1) {
  cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
  cast.player.api.setLoggerLevel(cast.player.api.LoggerLevel.DEBUG);
}

var mediaElement = document.getElementById('vid');
var protocol = null;
// Create the media manager. This will handle all media messages by default.
window.mediaManager = new cast.receiver.MediaManager(mediaElement);
window.defaultOnLoad = mediaManager.onLoad;
mediaManager.onLoad = function (event) {
  if (window.player !== null) {
    player.unload();    // Must unload before starting again.
    window.player = null;
  }
  if (event.data['media'] && event.data['media']['contentId']) {
    console.log('Starting media application');
    var url = event.data['media']['contentId'];
    window.host = new cast.player.api.Host({'mediaElement':mediaElement, 'url':url});
    var ext = url.substring(url.lastIndexOf('.'), url.length);
    var initStart = event.data['media']['currentTime'] || 0;
    var autoplay = event.data['autoplay'] || true;
    mediaElement.autoplay = autoplay;  // Make sure autoplay get's set

    if (url.lastIndexOf('.m3u8') >= 0) 
    {
      // HTTP Live Streaming
      protocol = cast.player.api.CreateHlsStreamingProtocol(host);
    } 
    else if (url.lastIndexOf('.mpd') >= 0) 
    {
      // MPEG-DASH
      protocol = cast.player.api.CreateDashStreamingProtocol(host);
    } 
    else if (url.indexOf('.ism/') >= 0) 
    {
      // Smooth Streaming
      protocol = cast.player.api.CreateSmoothStreamingProtocol(host);
    }
    // How to override a method in Host. I know that it's safe to just provide this
    // method.
    host.onError = function(errorCode) {
      console.log("Fatal Error - " + errorCode);
      if (window.player) {
        window.player.unload();
        window.player = null;
      }
    };
    console.log("we have protocol " + ext);
    if (protocol !== null) {
      console.log("Starting Media Player Library");
      window.player = new cast.player.api.Player(host);
      window.player.load(protocol, initStart);
      changeLanguage();
    }
    else {
      window.defaultOnLoad(event);    // do the default process
    }
  }
}

window.changeLanguage = function() {
 var currentLanguage = null;
 var streamCount = protocol.getStreamCount();
 console.log("streamCount: " + streamCount);
 var streamInfo;
 for (var i = 0; i < streamCount; i++) {
   console.log("isStreamEnabled " + i + "? " + protocol.isStreamEnabled(i));
   if (protocol.isStreamEnabled(i)) {
     streamInfo = protocol.getStreamInfo(i);
     console.log("streamInfo isAudio? " + streamInfo.mimeType.indexOf('audio'));
     if (streamInfo.mimeType.indexOf('audio') === 0) {
       if (streamInfo.language) {
     console.log("streamInfo.language: " + streamInfo.language);
     currentLanguage = i;
     break;
       }
     }
   }
 }

 if (currentLanguage === null) {
   currentLanguage = 0;
 }

 i = currentLanguage + 1;
 console.log("i: " + i);
 console.log("currentLanguage: " + currentLanguage);
 while (i !== currentLanguage) {
   if (i === streamCount) {
     console.log("resetting i to 0");
     i = 0;
   }

   streamInfo = protocol.getStreamInfo(i);
   if (streamInfo.mimeType.indexOf('audio') === 0) {
     protocol.enableStream(i, true);
     protocol.enableStream(currentLanguage, false);

     console.log("Enabling: " + i);
     console.log("Disabling: " + currentLanguage);
     break;
   }

   i++;
 }

 if (i !== currentLanguage) {
   console.log("reloading window player" + window.player);
   window.player.reload();
 }
};

window.player = null;
console.log('Application is ready, starting system');
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
castReceiverManager.start();
</script>
</body>
</html>

Chromecast 控制台:

应用程序准备就绪,启动系统

启动媒体应用程序

我们有协议 .ism/manifest

启动媒体播放器库

流计数:0

我:1

当前语言:0

编辑

我进入控制台并加载调用以下命令:

this.protocol.getStreamCount()

2

所以这显然是一个时间问题。流完全加载后,我需要调用 changeLanguage。我正在调查什么时候打电话给它。我会很感激任何帮助,但我会尝试用谷歌搜索这个答案,因为我很肯定这是一个时间问题。

4

1 回答 1

1

答案是:

host.onManifestReady = function() {
  changeLanguage();
};

这将为何时拉出备用音轨提供正确的时间。

于 2014-12-18T02:34:55.423 回答