【问题标题】:Chromecast API Sender - Android PhoneChromecast API 发件人 - Android 手机
【发布时间】:2015-03-23 10:32:21
【问题描述】:

我尝试为 chromecast 编写一些 webapps 以将我自己的网站投射到 chromecast。 chrome 桌面上的一切都很棒。我能够连接到 chromecast 发送消息和...

但是当我从手机上的 chrome 浏览器加载网站时,每次我想向我的接收者发送消息时,它总是说连接到 chromecast。

我不想为手机编写应用程序并希望将其保留在 webapp 上。

这是来自 SDK Developer 的示例代码。

<head>

<script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
<meta charset="utf-8">
</script>
<script type="text/javascript">
var applicationID = 'HIDDEN';
var namespace = 'urn:x-cast:com.google.cast.test';
var session = null;
var sessionID = null;

/**
 * Call initialization for Cast
 */
if (!chrome.cast || !chrome.cast.isAvailable) {
    setTimeout(initializeCastApi, 1000);
}

/**
 * initialization
 */
function initializeCastApi() {
    var sessionRequest = new chrome.cast.SessionRequest(applicationID);
    var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
        sessionListener,
        receiverListener);

    chrome.cast.initialize(apiConfig, onInitSuccess, onError);
};

/**
 * initialization success callback
 */
function onInitSuccess() {
    appendMessage("onInitSuccess");
}

/**
 * initialization error callback
 */
function onError(message) {
    appendMessage("onError: "+JSON.stringify(message));
}

/**
 * generic success callback
 */
function onSuccess(message) {
    appendMessage("onSuccess: "+message);
}

/**
 * callback on success for stopping app
 */
function onStopAppSuccess() {
    appendMessage('onStopAppSuccess');
}

/**
 * session listener during initialization
 */
function sessionListener(e) {
    appendMessage('New session ID:' + e.sessionId);
    session = e;
    session.addUpdateListener(sessionUpdateListener);  
    session.addMessageListener(namespace, receiverMessage);
    sessionID = session.sessionId;
}

/**
 * listener for session updates
 */
function sessionUpdateListener(isAlive) {
  var message = isAlive ? 'Session Updated' : 'Session Removed';
  message += ': ' + session.sessionId;
  appendMessage(message);

  if (!isAlive) {
    session = null;
  }
};

/**
 * utility function to log messages from the receiver
 * @param {string} namespace The namespace of the message
 * @param {string} message A message string
 */
function receiverMessage(namespace, message) {
  appendMessage("receiverMessage: "+namespace+", "+message);
};

/**
 * receiver listener during initialization
 */
function receiverListener(e) {
  if( e === 'available' ) {
    appendMessage("receiver found");
   // load();
  }
  else {
    appendMessage("receiver list empty");
  }
}

/**
 * stop app/session
 */
function stopApp() {
  session.stop(onStopAppSuccess, onError);
}

/**
 * send a message to the receiver using the custom namespace
 * receiver CastMessageBus message handler will be invoked
 * @param {string} message A message string
 */
function sendMessage(message) {
  if (session!=null) {
    session.sendMessage(namespace, message, onSuccess.bind(this, "Message sent: " + message), onError);
  }
  else {
    chrome.cast.requestSession(function(e) {
        session = e;
        session.sendMessage(namespace, message, onSuccess.bind(this, "Message sent: " + message), onError);
      }, onError);
  }
}

/**
 * append message to debug message window
 * @param {string} message A message string
 */
function appendMessage(message) {
  console.log(message);
//    var dw = document.getElementById("debugmessage");
//    dw.innerHTML += '\n' + JSON.stringify(message);
};

/**
 * utility function to handle text typed in by user in the input field
 */
function update() {
  sendMessage(document.getElementById("input").value);
}

/**
 * handler for the transcribed text from the speech input
 * @param {string} words A transcibed speech string
 */
function transcribe(words) {
    sendMessage(words);
}

</script>

</head>

我调用函数 transcribe 并将消息发送到我编写的 chrome 接收器。它在桌面版本上完美运行。但是在电话上它一直说连接到 chrome cast。

有人知道在手机上工作是否有强制设置?

【问题讨论】:

  • 我知道很多人会告诉我桌面和ios的演员表不一样,我必须使用IOS API。这是示例:github.com/googlecast/CastHelloText-ios 但是我不想创建一个应用程序,我只想在桌面以及任何手机、平板电脑上使用我的 web 应用程序......那么该怎么做呢?

标签: android chromecast


【解决方案1】:

我已经进行了越来越多的研究,并在 Stackflow 上找到了一些关于此问题的其他线程。

How can I send a message to a custom Google Cast Receiver from Chrome for iOS?

似乎不可能,因为它没有集成到手机上的 chrome 中。

但是,有谁知道 chromecats 是否支持其他通信方式。发送者和接收者?

【讨论】:

    猜你喜欢
    • 2013-08-04
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 2018-10-18
    • 2013-12-19
    • 2014-05-12
    相关资源
    最近更新 更多