我試圖在我的 接收器應用程序上初始化投射消息總線。我正在使用 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