AirPlay library for iOS
Installation with Automatic Linking
npm i react-native-airplay-ios --savereact-native link
Check the example project
Make sure to enable Swift support in your project, if you haven't done it yet. Xcode -> New file -> Swift file -> Create bridging headers
How to create listeners
// Setups native listeners which detect audio output route changesAirPlaythisairPlayConnected = AirPlayListener; --> returns a boolean// Remove Listener in componentWillUnmountthisdeviceConnected;
Also you can import
withAirPlayControl hoc and wrap your view component like so:
type Device =deviceName: stringportName: stringtype Props =devices: Device// Shows currently connected audio output devicesconst AirPlayDevices =
Devices is an array of objects that contains information about currently connected audio output(s):
deviceName: "Some Bluetooth Headphones Model" portType: "BluetoothA2DPOutput"// ordeviceName: "Speakers" portType:"Speakers"// ordeviceName: "Andrey’s Apple TV" portType: "AirPlay"
Probably it could just be an object, but internally AVAudioSessionRouteDescription returns array, so there might be a case when there is more than one device connected at the time.
Create AirPlay Button
Source is optional, as well as the states. You can pass a single state if you want, or don't pass this prop at all. The string is base64 encoded image. The size of image is 29x29. This limitation is due to the fact that AirPlayButton is a native component under the hood. It uses MPVolumeView to show routes button.
Note: The AirPlay Button does not show in the simulator
Original author of the library:
Andrey Efremov (gazedash)
Pull requests are welcome!