【发布时间】:2019-08-19 02:22:26
【问题描述】:
我目前正在使用 Cordova 开发一个 Android 应用程序。到目前为止这工作正常,但现在我想向 UI 添加一个 Chromecast 按钮,它似乎不起作用。我按照此处提供的说明进行操作:https://developers.google.com/cast/docs/chrome_sender/integrate
这就是我的代码到目前为止的样子:
var CastPlayer = function() {
//...
/* Cast player variables */
/** @type {cast.framework.RemotePlayer} */
this.remotePlayer = null;
/** @type {cast.framework.RemotePlayerController} */
this.remotePlayerController = null;
//...
};
var castPlayer = new CastPlayer();
window['__onGCastApiAvailable'] = function(isAvailable) {
if (isAvailable) {
castPlayer.initializeCastPlayer();
}
};
我的 index.html 中的内联脚本。
CastPlayer.prototype.initializeCastPlayer = function() {
var options = {};
// Set the receiver application ID to your own (created in the
// Google Cast Developer Console), or optionally
// use the chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID
options.receiverApplicationId = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
// Auto join policy can be one of the following three:
// ORIGIN_SCOPED - Auto connect from same appId and page origin
// TAB_AND_ORIGIN_SCOPED - Auto connect from same appId, page origin, and tab
// PAGE_SCOPED - No auto connect
options.autoJoinPolicy = chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED;
cast.framework.CastContext.getInstance().setOptions(options);
this.remotePlayer = new cast.framework.RemotePlayer();
this.remotePlayerController = new cast.framework.RemotePlayerController(this.remotePlayer);
this.remotePlayerController.addEventListener(
cast.framework.RemotePlayerEventType.IS_CONNECTED_CHANGED,
this.switchPlayer.bind(this)
);
};
我的 index.js 的内容。
在 index.html 中,我添加了这样的按钮:
<google-cast-launcher id="castbutton"></google-cast-launcher>
现在,当我通过浏览器(Chrome 和 Chromium)打开我的 Cordova 应用程序时,会显示投射按钮,我可以正常使用它。当我在 Android 上打开应用程序时,按钮不显示。有谁知道这是什么原因造成的,是否可以解决?
【问题讨论】:
-
Chromecast 是您无法添加/安装任何扩展程序的扩展程序。
标签: android cordova webview chromecast