React Native Google Cast
A React Native library to use Google Cast, based on react-native-google-cast
Getting started
$ npm install rn-google-cast --save
Installation
$ react-native link rn-google-cast
Notes:
- RN 0.60+ can use Autolinking
- tested only with RN 0.60+
Setup
Android
-
Make sure the device you're using (also applies to emulators) has Google Play Services installed.
-
Add this to your
android/build.gradle
:...ext{...castFrameworkVersion = "18.0.0"}... -
Add this dependencies to your
android/app/build.gradle
:dependencies{...implementation "com.google.android.gms:play-services-cast-framework:${rootProject.ext.castFrameworkVersion}"} -
Add to
androidmanifest.xml
:<!-- Add this permissions -->...<!-- Add these lines after <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> --> -
On your
MainActivity.java
:// default imports...// add these imports -
Done!
iOS
-
in your
AppDelegate.m
add: Google Cast SDK import#import <GoogleCast/GoogleCast.h>Aditional setup
...- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{...// add thisGCKDiscoveryCriteria *criteria = [[GCKDiscoveryCriteria alloc] initWithApplicationID:kGCKDefaultMediaReceiverApplicationID];GCKCastOptions* options = [[GCKCastOptions alloc] initWithDiscoveryCriteria:criteria];options.physicalVolumeButtonsWillControlDeviceVolume = YES; // add this row[GCKCastContext setSharedInstanceWithOptions:options];[GCKCastContext sharedInstance].useDefaultExpandedMediaControls = YES;return YES;} -
Done!
Usage
See example application