Chrome Sender: media.playerState is not properly updated

319 views Asked by At

I'm working on Chrome Sender application now and noticed that media.playerState was not properly updated to chrome.cast.media.PlayerState.PLAYING when play request is successfully executed. I understand that it's possible to subscribe to media state update via media.addUpdateListener(onMediaUpdate); but it's not very convenient. Are there any plans to make API more consistent?

/**
 * @param {chrome.cast.media.Media} media
 * @return {Promise.defer}
 */
function playMedia(media) {
  let playDefer = Promise.defer();
  let playRequest = new chrome.cast.media.PlayRequest();

  media.play(playRequest, onPlaySuccess.bind(null, playDefer, media), onPlayError); 

  return playDefer;
}

/**
 * @param {Promise.defer} defer
 * @param {chrome.cast.media.Media} media
 */
function onPlaySuccess(defer, media) {
  // Actually `media.playerState` is still chrome.cast.media.PlayerState.PAUSED
  // Is it expected behaviour? 
  console.log('play request success', media.playerState === chrome.cast.media.PlayerState.PLAYING);
  defer.resolve(media);
}

/**
 * @param {chrome.cast.Error} error
 */
function onPlayError(error) {
  console.log(error.code, error.description);
}
0

There are 0 answers