Google cast Chromecast无介质定制接收器
我想用Chromecast显示一个网页。目前该页面非常简单(只是“Hello World!”),但我希望它更复杂,并且可能与第二个屏幕交互。但是,我发现,如果我不创建媒体管理器(Google cast Chromecast无介质定制接收器,google-cast,chromecast,Google Cast,Chromecast,我想用Chromecast显示一个网页。目前该页面非常简单(只是“Hello World!”),但我希望它更复杂,并且可能与第二个屏幕交互。但是,我发现,如果我不创建媒体管理器(new cast.receiver.MediaManager(window.mediaElement)),会话将立即在我的发送方过期(调用函数sessionUpdateListener(false))。页面仍然显示,但我无法再与之交互,包括停止应用程序 我想知道这是不是出于设计,是一个bug,还是我做错了什么 这是我的自
new cast.receiver.MediaManager(window.mediaElement)
),会话将立即在我的发送方过期(调用函数sessionUpdateListener(false)
)。页面仍然显示,但我无法再与之交互,包括停止应用程序
我想知道这是不是出于设计,是一个bug,还是我做错了什么
这是我的自定义接收器的代码
<html>
<head>
<title>Hello World Chromecast App</title>
<style type="text/css">
*
{
color: white;
}
</style>
</head>
<body>
<div>Hello World!</div>
<script src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript">
window.onload = function () {
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
window.castReceiverManager.start();
}
</script>
</body>
</html>
Hello World Chromecast应用程序
*
{
颜色:白色;
}
你好,世界!
window.onload=函数(){
window.castrecivermanager=cast.receiver.castrecivermanager.getInstance();
window.castrecivermanager.start();
}
这是设计的。您有两个选择:
1) 创建媒体管理器
window.mediaElement = document.getElementById('receiverVideoElement');
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);
或者
2) 为消息总线创建自定义命名空间
// create a CastMessageBus to handle messages for a custom namespace
window.messageBus =
window.castReceiverManager.getCastMessageBus(
'urn:x-cast:com.google.cast.sample.firework');
否则,接收方将终止发送方会话。请注意,如果不满足上述任一条件,强制转换操作仍然有效,但发送方无法与接收方进一步通信。为了在发送方和接收方之间交换消息,您需要定义通信通道和协议(命名空间) 当要使用的协议与媒体相关(加载、播放、暂停…)时,您可以使用MediaManager为您执行此操作,也可以创建自己的协议。MediaManager在引擎盖下创建了一个新的应用程序 要创建自己的通信通道和协议,您需要获得或 如果未注册任何通信通道和协议(命名空间),则发送方将无法与应用程序通信 对于示例接收器,请参阅。如您所见,它创建了自己的CastMessageBus来交换JSON消息: TicTacToe.PROTOCOL='urn:x-cast:com.google.cast.demo.TicTacToe'; 这是一辆公共汽车= 这是.castrecivermanager_uu.getCastMessageBus(TicTacToe.PROTOCOL, cast.receiver.CastMessageBus.MessageType.JSON)
协议只是一个唯一的字符串,以“urn:x-cast:”开头,您可以定义它,并且接收方和发送方必须使用它来标识协议。诀窍在于,您需要在创建消息总线后调用start。一旦这样做,会话将在发送方上保持活动状态
<script type="text/javascript">
(function () {
var mgr;
var bus;
window.onload = function () {
mgr = cast.receiver.CastReceiverManager.getInstance();
bus = mgr.getCastMessageBus('urn:x-cast:com.sample.hello');
mgr.start();
}
})();
</script>
(功能(){
风险经理;
无功母线;
window.onload=函数(){
mgr=cast.receiver.CastReceiverManager.getInstance();
bus=mgr.getCastMessageBus('urn:x-cast:com.sample.hello');
经理启动();
}
})();
我已经试过了,但是没有用(bus=mgr.getCastMessageBus('urn:x-cast:com.redwerb.hello',cast.receiver.CastMessageBus.MessageType.JSON);)。我甚至在我的发件人中添加了一个侦听器(_session.addMessageListener('urn:x-cast:com.redwerb.hello',messageListener.bind(this))),但会话仍然会立即退出,Chrome开发者控制台中不会记录任何错误。我错过了什么?如果您愿意,我可以给您发送我的项目的zip文件(仅3个文件),只需告诉我将其放置在何处。顺便说一句,我已将该项目附加到我创建的票证上,以备您查看()。