我正在使用Chrome Sender应用程序,并注意到在成功执行播放请求时media.playerState
未正确更新为chrome.cast.media.PlayerState.PLAYING
。我知道可以通过media.addUpdateListener(onMediaUpdate);
订阅媒体状态更新,但这不太方便。有没有计划让API更加一致?
/**
* @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);
}