Chromecast Receiver App-意外命令,播放器处于空闲状态 [英] Chromecast Receiver App - Unexpected command, player is in IDLE state

查看:180
本文介绍了Chromecast Receiver App-意外命令,播放器处于空闲状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用演员参考播放器示例代码来开发接收器应用程序。我正在使用强制转换消息总线发送将启动媒体的JSON字符串。

I am using the cast reference player sample code to develop a receiver application. I am using the cast message bus to send a JSON string that will launch my media.

因此,在我的 player.html 中,我启动了广播消息总线。当我接收要播放的媒体的JSON 时,我从 player.js > player.html 就像这样:

So in my player.html, I init the cast message bus. When I receive JSON of the media that I want to play, I init player.js from player.html like so:

//receive message to play -> pass media through
var player = document.getElementById('player');
new sampleplayer.CastPlayer(player).start();

然后在我的 player.js 中:

sampleplayer.CastPlayer.prototype.start = function() {
  var self = this;
  var message = //JSON string
  this.load(JSON.parse(message));

  var millisecondsToWait = 8000;
  setTimeout(function() {
    //Pause Works
    self.mediaElement_.pause();
  }, millisecondsToWait);

  var millisecondsToWait = 10000;
  setTimeout(function() {
    //Play Works
    self.mediaElement_.play();
  }, millisecondsToWait);
};

我能够启动媒体,可以使用上面的代码播放/暂停媒体。

I am able to launch the media, I can play/ pause the media with the code above.

当我尝试使用遥控器上的播放/暂停按钮时,出现以下错误:
[cast.receiver.MediaManager ]意外命令,播放器处于IDLE状态,因此媒体会话ID无效

When I try use the play/ pause button on my remote control, I get the following error: [cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet.

我也没有得到任何我以前得到的 PlayState 更新。

I also don't get any of the PlayState updates that I was previously getting.

我相信我没有初始化正确的东西,但是我不确定是什么。有人知道我有一个好的起点吗?谢谢

I believe I am not initialising something right, but I'm not sure what. Does anyone know of a good starting point for me? Thanks

推荐答案

我希望这可以帮助某人。

I hope this can help someone.

我可以使用 playerManager.load(loadRequestData) playerManager.play()成功地使用PlayerManger加载并开始播放视频。但是,一旦我停止使用 playerManager.stop(),然后尝试再次播放,我就经常遇到此错误:

I could successfully load and start a video with the PlayerManger using playerManager.load(loadRequestData) and playerManager.play(). However, once I stopped using playerManager.stop() and then tried to play again, I used to get this error:

[cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet

之所以会这样,是因为 playerManager.stop()方法从标记中卸载了视频。

This happens because the playerManager.stop() method unloads the video from the tag.

要解决此问题,只需在播放之前检查视频是否已加载。

To fix this behaviour, just check if a video is loaded before playing.

示例:

if (isNaN(playerManager.getDurationSec())) {
    // the player has been stopped, then I reload the video
    // Load with autoplay: playerManager.load(loadRequestData);
}
else {
    playerManager.play();
}

这篇关于Chromecast Receiver App-意外命令,播放器处于空闲状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆