Installation
$ npm install react-native-google-cast --save
or
$ yarn add react-native-google-cast
Expo
Since Expo SDK 42, you can use this library in a custom-built Expo app.
Simply follow instructions at @config-plugins/react-native-google-cast which will take care of all the installation and setup steps.
Then ignore the rest of this page and jump straight to Usage.
If you're unsure please check the example Expo app.
iOS
a. Autolinking (recommended)
By default, the package installs the NoBluetoothArm
dependency, which is compatible with ARM Macs and doesn't enable Guest Mode (which requires an extra set of Bluetooth permissions that are not needed for many use cases).
cd ios && pod install
Note that the latest Google Cast SDK (currently 4.8.0), as well as this package, only supports iOS 13 or newer. If you need to support older iOS versions, please use an older version of the library but note that some features might not be available.
b. Custom version or guest mode
However, if you'd like to install a different version of the Google Cast SDK:
In your
ios/Podfile
, add one of these snippets:i. If you don't need guest mode and want to develop on an ARM Mac (this is the default option), add
pod 'react-native-google-cast/NoBluetoothArm', path: '../node_modules/react-native-google-cast/'
ii. If you want to support guest mode, add (and don't forget step 5 in the Setup):
pod 'react-native-google-cast/GuestModeArm', path: '../node_modules/react-native-google-cast/'
iii. If you don't need to build on an ARM Mac, and you're having trouble installing the Arm version, you can use the
NoBluetooth
orGuestMode
dependency instead.pod 'react-native-google-cast/NoBluetooth', path: '../node_modules/react-native-google-cast/'
or for Guest Mode (don't forget step 5 in the Setup):
pod 'react-native-google-cast/GuestMode', path: '../node_modules/react-native-google-cast/'
If your
ios/Podfile
containsuse_native_modules!
(it's the default), you'll need to disable autolinking for this package, otherwise the dependency you added in the previous step will conflict with the autolinked one. To do so, createreact-native.config.js
in the root of your project with this content:module.exports = { dependencies: { 'react-native-google-cast': { platforms: { ios: null, // this will disable autolinking for this package on iOS }, }, }, }
Finally, run
pod install
.
Android
Insert the following into android/app/build.gradle
:
dependencies {
// ...
implementation "com.google.android.gms:play-services-cast-framework:${safeExtGet('castFrameworkVersion', '+')}"
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
By default, the latest version (+
) of the Cast SDK is used. To use a specific version, set it in the root android/build.gradle
:
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 16
compileSdkVersion = 31
targetSdkVersion = 31
supportLibVersion = "31.0.0"
castFrameworkVersion = "21.0.0" // <-- Cast SDK version
}
}
Chrome
Not supported yet