我正在构建基于[CAF SDK] [1]的自定义Chromecast接收器。我试图将接收器应用程序设置为IDLE
状态模式,以便在媒体结束后的5分钟内处理启动画面...
我试着用:
var video = document.createElement("video");
video.classList.add('castMediaElement');
video.style.setProperty('--splash-image', 'url("img/logo-mySplash.svg")');
document.body.appendChild(video);
var context = cast.framework.CastReceiverContext.getInstance();
context.setInactivityTimeout(300);
playerManager.addEventListener(cast.framework.events.EventType.ALL,
function (event) {
switch(event.type) {
case 'CLIP_ENDED':
context.setApplicationState('IDLE');
break;`
}
})
当媒体结束时,接收方发送:
{type: "CLIP_ENDED", currentMediaTime: 2673.986261, endedReason: "END_OF_STREAM"}
{type: "MEDIA_FINISHED", currentMediaTime: 2673.986261, endedReason: "END_OF_STREAM"}
并将错误发送到调试控制台:
[ 32.846s] [cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet
我找不到有关此问题的任何文档。无论如何,谢谢你的回答。
答案 0 :(得分:0)
context.setApplicationState
只是更新了应用的statusText
。请参阅:https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.CastReceiverContext#setApplicationState。
您可能想要做的是在playerDataBinder
事件cast.framework.ui.PlayerDataEventType.STATE_CHANGED
上添加一个监听器。这样,只要state
属性发生更改,您就可以看到待机屏幕。
此外,为了充分利用CAF,您可能希望使用cast-media-player
元素。有关使用此元素而非自定义视频元素的好处的其他信息,请访问:https://developers.google.com/cast/docs/caf_receiver_features