我曾尝试为chromecast编写一些webapp,以便将我自己的网站投射到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>我调用函数转录,它会将消息发送到我编写的chrome接收器。它在桌面版本上工作得很好。但在电话里,它总是说连接到chrome cast。
有没有人知道在手机上工作有什么可以强制设置的?
发布于 2015-03-23 19:28:18
我做了越来越多的研究,在Stackflow上找到了关于这个问题的其他一些帖子。
How can I send a message to a custom Google Cast Receiver from Chrome for iOS?
这似乎是不可能的,因为它没有集成到手机上的铬。
但是,有没有人知道chromecats是否支持btw的其他通信方式。发送者和接收者?
https://stackoverflow.com/questions/29208008
复制相似问题