1. Help
  2. Developer Documentation & APIs
  3. Chromecast support for Cordova WebView

Chromecast support for Cordova WebView

By default WebView doesn’t support Chromecast API, to solve this we can use Cordova plugins for example https://github.com/miloproductionsinc/cordova-plugin-chromecast


This project attempts to implement the official Google Cast API for Chrome within the Cordova webview.
This means that you should be able to write almost identical code in cordova as you would if you were developing for desktop Chrome.In This plugin not implemented every function in the API but most of the core functions are there.
The most significant usage difference between the cast API and this plugin is the initialization.
In Chrome desktop you would do:

window['__onGCastApiAvailable'] = function(isAvailable, err) {
  if (isAvailable) {
    // start using the api!
  }
};

But in cordova-plugin-chromecast you do:

document.addEventListener("deviceready", function () {
  // start using the api!
});

Supports


  • Android 4.4+ (may support lower, untested)
  • iOS 10.0+ (The Google Cast iOS Sender SDK 4.5.0 says iOS 10+ but all tests on the plugin work fine for iOS 9.3.5, so it appears to work on iOs 9 anyways. :/)

Quirks


Android 4.4 (maybe 5.x and 6.x) are not able automatically rejoin/resume a chromecast session after an app restart.

Installation


cordova plugin add https://github.com/miloproductionsinc/cordova-plugin-chromecast.git

If you have trouble installing the plugin or running the project for iOS, from /platforms/ios/ try running:

sudo gem install cocoapods
pod repo update
pod install

Additional iOS Installation Instructions


To distribute an iOS app with this plugin you must add usage descriptions to your project’s config.xml.
The “*Description” key strings will be used when asking the user for permission to use the microphone/bluetooth/local network.
Check config instruction in plugin readme.

Example Usage


Here is a simple example that loads a video, pauses it, and ends the session.

Was this article helpful?