【发布时间】:2015-05-07 23:01:56
【问题描述】:
我正在尝试构建一个简单的基于 JS 的 Web 应用程序,它启动一个样式化的媒体接收器(由 Google 托管,读取您的自定义 CSS 文件)。我设置了一个开发者帐户,并已将应用程序添加到我的帐户中。我在创建时确保选择了“Styled Media Receiver”类型。
我正在使用here 描述的基本设置来构建我的发件人。我能够让此代码与自定义接收器一起使用。我可以在我的日志中看到检测到扩展。
Found cast extension: boadgeojelhgndaghljhdicfkmllpafd
我使用 Cast 开发者控制台上提供的应用 ID 设置会话请求。
var sessionRequest = new chrome.cast.SessionRequest(id);
然后我打电话:
var apiConfig = new chrome.cast.ApiConfig(this.sessionListener.bind(this),
this.receiverListener.bind(this));
这会将值“不可用”返回给“receiverListener”函数。当我尝试请求会话时,它会返回带有以下数据的错误回调:
Object {code: "receiver_unavailable", description: null, details: null}
所以,我想弄清楚我可能遗漏了什么。就像我说的那样,我已经使用相同的代码成功启动了自定义接收器。这是我正在使用的完整代码:
Polymer({
ready: function(){
window['__onGCastApiAvailable'] = function(loaded, errorInfo){
if(loaded){
this.initCast();
}
else{
console.log(errorInfo);
}
}.bind(this);
},
initCast: function(){
var id = "731AC858";
var sessionRequest = new chrome.cast.SessionRequest(id);
var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
this.sessionListener.bind(this),
this.receiverListener.bind(this));
chrome.cast.initialize(apiConfig,
this.initCastSuccess.bind(this),
this.initCastError.bind(this));
},
initCastSuccess: function(){
this.castReady = true;
},
initCastError: function(e){
console.log(e);
},
startCast: function(){
chrome.cast.requestSession(this.startCastSuccess.bind(this),
this.startCastError.bind(this));
},
startCastSuccess: function(e){
console.log(e);
},
startCastError: function(e){
console.log(e); //returns Object {code: "receiver_unavailable", description: null, details: null} when "startCast" is called.
},
sessionListener: function(e){
console.log(e);
},
receiverListener: function(e){
console.log(e);//returns "unavailable"
},
});
【问题讨论】:
-
你在写 chrome/打包的应用吗?
-
不,它是一个使用聚合物并部署在 Google App Engine 上的网络应用程序。此外,在本地开发服务器或部署服务器上的结果是相同的。