【问题标题】:Can't install Custom Receiver on Chromecast无法在 Chromecast 上安装自定义接收器
【发布时间】:2015-08-22 04:08:01
【问题描述】:

我每次尝试使用自定义接收器连接到 Chromecast 时都会收到消息 Application not installed。我相信问题可能是 1) 上传到 Chromecast 的错误过程。 2)JS代码中的一些错误(我不擅长它..)

自定义接收方代码。代码内部可能有错误。它应该将带有 Base 64 字符串的 JSON 消息解码为图像。

</head>
<body>
<img id="androidImage" src="" />
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript">
  window.onload = function() {
    cast.receiver.logger.setLevelValue(0);
    window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
    console.log('Starting Receiver Manager');

    // handler for the 'ready' event
    castReceiverManager.onReady = function(event) {
      console.log('Received Ready event: ' + JSON.stringify(event.data));
      window.castReceiverManager.setApplicationState("Application status is ready...");
    };

    // handler for 'senderconnected' event
    castReceiverManager.onSenderConnected = function(event) {
      console.log('Received Sender Connected event: ' + event.data);
      console.log(window.castReceiverManager.getSender(event.data).userAgent);
    };

    // handler for 'senderdisconnected' event
    castReceiverManager.onSenderDisconnected = function(event) {
      console.log('Received Sender Disconnected event: ' + event.data);
      if (window.castReceiverManager.getSenders().length == 0) {
        window.close();
      }
    };

    // handler for 'systemvolumechanged' event
    castReceiverManager.onSystemVolumeChanged = function(event) {
      console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
          event.data['muted']);
    };

    // create a CastMessageBus to handle messages for a custom namespace
    window.messageBus =
      window.castReceiverManager.getCastMessageBus(
          'urn:x-cast:com.it.innovations.smartbus');

    // handler for the CastMessageBus message event
    window.messageBus.onMessage = function(event) {
      console.log('Message recieved');

      var obj = JSON.parse(event.data)

      console.log('Message type: ' + obj.type);
      if (obj.type == "text") {
        console.log('Skipping message: ' + obj.data);
      }

      if (obj.type == "image") {
        var source = 'data:image/png;base64,'.concat(obj.data)
        displayImage(source);
      }

      // inform all senders on the CastMessageBus of the incoming message event
      // sender message listener will be invoked
      window.messageBus.send(event.senderId, event.data);
    }

    // initialize the CastReceiverManager with an application status message
    window.castReceiverManager.start({statusText: "Application is starting"});
    console.log('Receiver Manager started');
  };


  function displayImage(source) {
    console.log('received image');
    document.getElementById("androidImage").src=source;
    window.castReceiverManager.setApplicationState('image source changed');
  };

</script>

ps。命名空间与发送方应用中的相同。

Custom Receiver的安装过程:

  1. 使用上面的代码创建了 .js 文件(也尝试了 .html)。
  2. 将该文件托管在 Google Drive (link) 上。还尝试使用 .html 文件和直接下载文件的链接。
  3. 使链接世界可见。
  4. 在 Cast Console 中为字段 URL 中注册的自定义接收器添加了此链接
  5. 在注册接收方的发送方应用中使用APP ID。

似乎每次我连接到 Chromecast 时它都会尝试安装此接收器,但它需要几秒钟(屏幕为黑色)并崩溃并出现代码 15(超时)。我正在尝试默认的 APP ID,然后它正确连接到接收器,但它无法解码字符串。

我也无法通过 chromecast-ip:9222 调试接收器,因为它尚未安装。

如果有任何帮助,我将不胜感激。谢谢。

【问题讨论】:

    标签: javascript chromecast google-cast


    【解决方案1】:

    首先让我们解决您的托管问题。在开发接收器时使用 Google Drive 进行托管很好,但您需要遵循某些步骤以确保它被正确托管。请参考this page查看正确步骤;正确托管后,您的网址应类似于 www.googledrive.com/host/[doc id]

    【讨论】:

    • 是的,我完全按照它。但似乎谷歌禁用了托管。这就是this tutorial 所说的。我使用Google scripts 来托管它。
    • 我认为没有任何改变;按照手动步骤(而不是使用脚本)将您的 URL 注册为 https://www.googledrive.com/host/{doc id} 并将接收者的 URL 更新为这种格式,看看是否有效。
    • 好的,好像它托管了文件 - www.googledrive.com/host/0Bz2Lss3i7uJHZGRKLUx3amJLOTQ。但我无法将此链接放入 Cast Console,请参阅 this screen
    • 链接已通过。但是现在当我连接到 Chromecast 时,会出现一个黑屏,右侧有滚动条,持续 5-10 秒。之后我仍然在ApplicationConnectionResultCallback.onResult 中收到 TIMEOUT(15) 错误,这可能是什么原因?
    • 那么你需要调试接收器。当您的应用程序启动时,您可以尝试使用端口 9222 连接到您的 chrome 进行调试,看看您是否可以了解更多关于正在发生的事情;看来您原来的问题现在已经解决了。
    猜你喜欢
    • 2019-01-03
    • 2022-12-11
    • 2016-10-01
    • 2014-10-04
    • 2014-12-25
    • 2014-07-25
    • 2021-11-03
    • 2014-03-10
    相关资源
    最近更新 更多