Skip to content Skip to sidebar Skip to footer

Chromecast Receiver App - Unexpected Command, Player Is In Idle State

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 playe

Solution 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 isin IDLE state so the media session ID isnot 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)// create some queue itemsconst item = new cast.framework.messages.QueueItem()
  item.media = new cast.framework.messages.MediaInformation()
  item.media.contentId = '/movie.mp4'const items = [item]

  // Create a new queue with media.let queueData = new cast.framework.messages.QueueData()
  queueData.items = items

  // [cast.receiver.MediaManager] Media or QueueData is mandatoryconst loadRequestData = new cast.framework.messages.LoadRequestData()
  loadRequestData.queueData = queueData
  cast.framework.CastReceiverContext.getInstance()
    .getPlayerManager().load(loadRequestData)
}
else {
  playerManager.play()
}

Post a Comment for "Chromecast Receiver App - Unexpected Command, Player Is In Idle State"