В настоящее время я разрабатываю приложение для Android с использованием Cordova. Пока все работает нормально, но теперь, когда я хочу добавить кнопку 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>
Теперь, когда я открываю свое приложение Cordova через браузер (Chrome AND Chromium), отображается кнопка приведения и я могу использовать ее как обычно. Когда я открываю приложение на Android, кнопка просто не отображается. Кто-нибудь знает, что вызывает это, и если это может быть решено?