我正在使用演员参考播放器示例代码来开发接收器应用程序。我正在使用强制转换消息总线发送将启动媒体的JSON字符串。
因此,在我的player.html
中,我初始化了cast message bus
。当我要播放的媒体的receive JSON
时,我像这样从player.js
初始化player.html
:
//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);
};
我能够启动媒体,我可以使用上面的代码播放/暂停媒体。
当我尝试使用遥控器上的播放/暂停按钮时,出现以下错误:[cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet
。
我也没有得到以前得到的任何PlayState
更新。
我相信我没有初始化正确的东西,但是我不确定是什么。有人知道我有一个好的起点吗?谢谢
我希望这可以帮助某人。
我可以使用playerManager.load(loadRequestData)
和playerManager.play()
成功地使用PlayerManger加载和启动视频。但是,一旦我停止使用playerManager.stop()
,然后尝试再次播放,我就遇到了此错误:
[cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet
发生这种情况是因为playerManager.stop()
方法从标记中卸载了视频。
要解决此问题,只需在播放之前检查视频是否已加载。
实施例:
if (isNaN(playerManager.getDurationSec())) {
// the player has been stopped, then I reload the video
// Load with autoplay: playerManager.load(loadRequestData);
}
else {
playerManager.play();
}