Chromecast Receiver App - Unexpected command, play

2019-03-04 07:27发布

问题:

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