Chromecast Receiver App - Unexpected command, player is in IDLE state

微笑、不失礼 提交于 2019-12-04 06:10:16

问题


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.

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();

then in my 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.

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.

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


回答1:


I hope this can help someone.

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

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.

Example:

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


来源:https://stackoverflow.com/questions/43366352/chromecast-receiver-app-unexpected-command-player-is-in-idle-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!