![](/img/trans.png)
[英]Chromecast Custom Receiver player stuck on an IDLE state and doesn't respond
[英]Chromecast Receiver App - Unexpected command, player is in IDLE state
我正在使用演員參考播放器示例代碼來開發接收器應用程序。 我正在使用 cast 消息總線發送一個 JSON 字符串,該字符串將啟動我的媒體。
所以在我的player.html
,我初始化了cast message bus
。 當我receive JSON
我想播放的媒體的receive JSON
時,我從player.html
初始化player.js
, player.html
所示:
//receive message to play -> pass media through
var player = document.getElementById('player');
new sampleplayer.CastPlayer(player).start();
然后在我的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);
};
我能夠啟動媒體,我可以使用上面的代碼播放/暫停媒體。
當我嘗試使用遙控器上的播放/暫停按鈕時,出現以下錯誤: [cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet
。
我也沒有獲得我之前獲得的任何PlayState
更新。
我相信我沒有正確初始化某些東西,但我不確定是什么。 有誰知道對我來說一個好的起點? 謝謝
我希望這可以幫助某人。
我可以成功地加載和使用開始與PlayerManger視頻playerManager.load(loadRequestData)
和playerManager.play()
但是,一旦我停止使用playerManager.stop()
然后嘗試再次播放,我曾經收到此錯誤:
[cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet
發生這種情況是因為playerManager.stop()
方法從標簽中卸載視頻。
要解決此問題,只需在播放前檢查視頻是否已加載。
例子:
if (isNaN(playerManager.getDurationSec())) {
// the player has been stopped, then I reload the video
// Load with autoplay: playerManager.load(loadRequestData)
// create some queue items
const 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 mandatory
const loadRequestData = new cast.framework.messages.LoadRequestData()
loadRequestData.queueData = queueData
cast.framework.CastReceiverContext.getInstance()
.getPlayerManager().load(loadRequestData)
}
else {
playerManager.play()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.