【问题标题】:Unable to connect to styled receiver无法连接到样式接收器
【发布时间】: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 上的网络应用程序。此外,在本地开发服务器或部署服务器上的结果是相同的。

标签: javascript google-cast


【解决方案1】:

看来我要么不耐烦,应用程序需要一段时间才能消化,要么托管 Styled 媒体接收器的服务器关闭了一段时间。我今天试了一下,一切正常。

----更新----

我刚刚尝试创建一个风格新颖的媒体接收器应用程序,但无法连接。所以我的猜测是,在你开始使用它之前,必须先准备一些东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-06
    • 2019-12-20
    • 2021-08-25
    相关资源
    最近更新 更多