更新媒体信息时不会调用onRemoteMediaPlayerMetadataUpdated

时间:2015-01-28 12:54:46

标签: chromecast google-cast

我正在研究Chromecast Receiver应用程序并尝试引入排队逻辑。决定在接收器侧保持排队逻辑,以便当当前音轨完成时,在接收器侧选择下一个音轨。应该会通知所有发件人应用程序此更改。

不幸的是,当接收方发送媒体信息更新时,发送方不会调用onRemoteMediaPlayerMetadataUpdated回调。

我们的方法受到github在{{3}}上找到的CastVideosPlaylist应用的启发。我们不等待loadedmetadata的原因是因为发件人对duration等元信息不感兴趣。

非常感谢任何帮助。

谢谢。

我们使用的代码看起来非常像这样。

var mediaElement = new Audio();
var mediaManager = new cast.receiver.MediaManager(mediaElement);

mediaManager.onEnded = (function(){

  var origFn = mediaManager.onEnded;

  return function(event) {
    // passing the control to Chromecast Media Manager
    origFn.call(mediaManager, event);

    var nextTrack = getNextTrack();

    if (nextTrack) {
      var mediaInfo = new cast.receiver.media.MediaInformation();

      mediaInfo.duration = nextTrack.duration;
      mediaInfo.contentId = nextTrack.contentId;
      mediaInfo.streamType = 'BUFFERED';
      mediaInfo.contentType = 'audio/mpeg';

      // broadcasting information about next track to all senders
      mediaManager.setMediaInformation(mediaInfo);

      // rendering a new player
      renderTrackView(nextTrack);
    }
  }

}());

mediaManager.setMediaInformation = (function() {
  var origFn = mediaManager.setMediaInformation.bind(mediaManager);

  // redefining `MediaManager#setMediaInformation` so that a play queue is sent back to senders
  // whenever a media information is updated
  return function(mediaInformation, opt_broadcast, opt_broadcastStatusCustomData) {
    mediaInformation.customData = {
      play_queue: playQueue.getTracks()
    };
    origFn(mediaInformation, opt_broadcast, opt_broadcastStatusCustomData);
  }
}());

0 个答案:

没有答案