以下代码显示了我网络上可用的chromecast设备的正确列表。但是当我点击链接时,应用程序永远不会启动。有一些我很困惑的事情可能与这个问题有关,也可能没有:
应该注意的是,我的发件人应用是镀铬网页。
我对我的“appid”在启动参数中的位置感到有点困惑,'
<html data-cast-api-enabled="true">
<body>
hi!<BR/>
<script>
var cast_api, cv_activity;
if (window.cast && window.cast.isAvailable) {
// Cast is known to be available
initializeApi();
} else {
// Wait for API to post a message to us
window.addEventListener("message", function(event) {
if (event.source == window && event.data &&
event.data.source == "CastApi" &&
event.data.event == "Hello")
{
//document.write("Initialize via message.<br/>");
initializeApi();
//document.write("Api initialized via message.");
};
});
};
initializeApi = function() {
cast_api = new cast.Api();
cast_api.addReceiverListener("YouTube", onReceiverList);
};
var g_list;
onReceiverList = function(list) {
g_list = list;
// If the list is non-empty, show a widget with
// the friendly names of receivers.
// When a receiver is picked, invoke doLaunch with the receiver.
document.write("Receivers: "+list.length+"<br/>");
var t;
for(t=0;t<list.length;t++)
document.write('found:<a href="javascript:launchy('+t+')">'+list[t].name+'</a> ' +list[t].id+'<br/>');
};
onLaunch = function(activity) {
if (activity.status == "running") {
cv_activity = activity;
// update UI to reflect that the receiver has received the
// launch command and should start video playback.
} else if (activity.status == "error") {
cv_activity = null;
}
};
function launchy(idx)
{
doLaunch(g_list[idx]);
}
doLaunch = function(receiver) {
var request = new window.cast.LaunchRequest(">>>>>what REALLY goes here?<<<<<<< ", receiver);
request.parameters = "v=abcdefg";
request.description = new window.cast.LaunchDescription();
request.description.text = "My Cat Video";
request.description.url = "http://my.website.get.your.own/chomecast/test.php";
cast_api.launch(request, onLaunch);
};
stopPlayback = function() {
if (cv_activity) {
cast_api.stopActivity(cv_activity.activityId);
}
};
</script>
</body>
</html>
部分标记为“这里到底是什么?”是我认为错误的部分......我不能完全错。我的设备是白名单,我有一个appid(我认为可能会在那个插槽中)...文档只是说ActivityType DIAL Parmeters是有效的,强制性的。
答案 0 :(得分:1)
LaunchRequest的第一个参数是您的App ID,即您在电子邮件中收到的作为白名单流程一部分的ID。此外,初始化方法中的“YouTube”也应替换为相同的应用程序ID。
我强烈建议您查看GitHub上针对Chrome发送者的示例,以了解如何发送在转换设备上加载媒体的请求。