从Android发件人应用上的com.google.cast.media命名空间接收数据消息

时间:2014-06-07 00:54:02

标签: android chromecast google-cast

我为Chromecast创建了一个播放视频的自定义接收器,我正在尝试将消息发送回同一命名空间中的Android发送器应用。我目前正在Javascript中这样做:

window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
window.castReceiverManager.start();

//use namespace urn:x-cast:com.google.cast.media to communicate to VideoCastManager in Android...?
window.customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:com.google.cast.media', cast.receiver.CastMessageBus.MessageType.JSON);

//overwrite the onMessage function
var defaultFunction = window.customMessageBus.onMessage;
window.customMessageBus.onMessage = function(event) {
  window.senderId = event.senderId;
  window.message = event.data;
  defaultFunction(event);
};

//send message
window.customMessageBus.send(window.senderId, {message: "test"});

在Android中,我试图以这种方式接收消息:

mCastConsumer = new VideoCastConsumerImpl() {
        //removed all the other override functions to save space

        @Override
        public void onDataMessageReceived(String message) {
            System.out.println("CAST RECEIVED MESSAGE:" + message);
        }

    };

这不起作用,我希望有人能指出我正确的方向吗?

由于

1 个答案:

答案 0 :(得分:2)

您需要使用自定义命名空间而不是Media命名空间。