我试图在我的 接收器应用程序上初始化投射消息总线。我正在使用 CastReferencePlayer Sample
(https://github.com/googlecast/CastReferencePlayer)我可以在启动时初始化通道,并且 会收到一条消息。Chromecast不通过CastMessageBus接收消息
但是在媒体播放后,我无法通过 发件人使用相同的send
方法在频道上收到 任何其他消息。我的发件人是iOS Device
哪里是启动消息总线的最佳位置,以确保通道 在应用程序的整个生命周期内都可以接收消息?
我目前在sampleplayer.CastPlayer.prototype.start = function()
开始频道 。但我不确定这是否是启动消息总线的正确位置,因为我只在启动时收到消息(即在媒体开始播放之前)。
sampleplayer.CastPlayer.prototype.start = function() {
var messageBus = this.receiverManager_.getCastMessageBus(
"urn:x-cast:com.myTestChannel.app",
cast.receiver.CastMessageBus.MessageType.JSON);
messageBus.onMessage = function(event) {
var message = event.data;
if (message.testID) {
console.log("Message received");
} else if (message.someKey) {
console.log("pause message received");
}
};
this.receiverManager_.start();
};
我试图放置信道创建代码在window.onload
函数我player.js
内部但这反应和以前一样(即仅初始消息)。
有没有人有任何想法,我应该放置代码来初始化通道? 任何帮助,将不胜感激。
编辑:我已经做了一些更多的调查,发现它只是我的iOS发送者不会向接收者发送多条消息。我已经尝试了Android和Chrome和多个消息的工作。 是否有人知道从iOS发件人发送邮件的问题。
由此引用此[SO帖子](http://stackoverflow.com/questions/39766944/sending-a-json-from-ios-sender-to-receiver-app-with-the-googlecast-sdk- v3),您需要创建['GCKCastChannel'](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a536d42cdfb9d56d9ed10c3f75c493985)实例(用于您的名称空间),并使用['sendTextMessage'] (https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a536d42cdfb9d56d9ed10c3f75c493985)。 – abielita
@abielita,感谢您的链接。我已经在正确的命名空间上创建了演员频道。我解决了我的问题。在我的实施中,我第一次使用它后,对演员频道的引用被破坏了。 – mhorgan