react-native-google-cast
A library that unifies both android and iOS chromecast sdk
Getting started
$ npm install react-native-google-cast --save
Mostly automatic installation
$ react-native link react-native-google-cast
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-google-cast
and addRNGoogleCast.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNGoogleCast.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNGoogleCastPackage;
to the imports at the top of the file - Add
new RNGoogleCastPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-google-cast' project(':react-native-google-cast').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-cast/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-google-cast')
iOS Heads Up
- This library requires Cocoapods to manage Chromecast SDK.
- Add
pod 'google-cast-sdk'
to your Podfile. This is the easier way to have the SDK up to date.
Android Heads Up
- This library requires Google Play Services to manage Chromecast SDK.
## Usage
// Require the module; // Init Chromecast SDK and starts looking for devices (uses DEFAULT APP ID)Chromecast; // Init Chromecast SDK and starts looking for devices using registered APP IDChromecast; // Does what the method says. It saves resources, use it when leaving your current viewChromecast; // Returns a boolean with the resultChromecast; // Return an array of devices' names and idsChromecast; // Gets the device id, and connects to it. If it is successful, will send a broadcastChromecast; // Closes the connection to the current ChromecastChromecast; // Streams the media to the connected chromecast. Time parameter let you choose// in which time frame the media should start streamingChromecast; // Move the streaming media to the selected time frameChromecast; // Toggle Chromecast between pause or play stateChromecast; // Get the current streaming time frame. It can be use to sync the chromecast to// your visual media controllersChromecast;
Events
Chromecast uses events to let you know when you should start playing with the service, like streaming the media.
// To know if there are chromecasts aroundDeviceEventEmitter; // To know if the connection attempt was successfulDeviceEventEmitter; // If chromecast started to stream the media succesfully, it will send this eventDeviceEventEmitter;
Constants
DEVICE_AVAILABLE DEVICE_CONNECTED DEVICE_DISCONNECTED MEDIA_LOADED
Example
Refer to the example folder to find an implementation of this project. Remember to use
pod install
react-native link react-native-google-cast
to try it!
Contribution
Contributions are welcome !