每次我尝试使用自定义接收器连接到Chromecast时,我都会收到消息Application not installed
。我认为问题可能是1)上传到Chromecast的过程错误。 2)JS代码中的一些错误(我对它不强..)
自定义接收器代码。可能是代码中的错误。它应该使用Base 64字符串解码JSON消息到Image。
</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。命名空间与发件人应用程序中的命名空间相同。
安装自定义接收器的过程:
似乎它每次连接到Chromecast时都会尝试安装此接收器但是它需要几秒钟(屏幕为黑色)并且代码15崩溃(超时)。我正在尝试默认的APP ID,然后它正确连接到接收器,但它无法解码字符串。
此外我无法通过 chromecast-ip:9222 调试接收器,因为它尚未安装。
我将不胜感激任何帮助。谢谢。
答案 0 :(得分:2)
首先让我们修复您的托管问题。在开发接收器时使用Google Drive进行托管是可以的,但您需要按照某些步骤确保托管正确。请参阅this page以查看正确的步骤;如果正确托管,您的网址应该像www.googledrive.com/host/ [doc id]