我目前正在使用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();
}
};
我的索引.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)
);
};
我的索引内容.js。
在索引.html中,我添加了这样的按钮:
<google-cast-launcher id="castbutton"></google-cast-launcher>
现在,当我通过浏览器(Chrome AND Chromium(打开我的Cordova应用程序时,会显示投射按钮,我可以正常使用它。当我在Android上打开应用程序时,按钮只是不显示。有谁知道是什么原因造成的,是否可以解决?
我们找不到科尔多瓦的解决方案,但在 Flutter 中管理了它。
我们遇到了同样的挑战,我们搜索了高低。终于找到了这个解决方案,使其适用于:https://pub.dev/packages/dart_chromecast
确保颤振编译器降级到 13 或更低。否则,您将无法编译。不幸的是,他们的代码在较新版本的 flutter 编译器中不受支持,作者不会很快更新。