react-native-airplay-btn
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 changesAirPlay thisairPlayConnected = AirPlayListener; --> returns a boolean // Remove Listener in componentWillUnmountthisdeviceConnected;
Also you can import withAirPlayControl
hoc and wrap your view component like so:
type Device = deviceName: string portName: string type 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"
Note:
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.
Methods
AirPlay; AirPlay;
Create AirPlay Button
;<AirPlayButton source= disabled: '' normal: '' focused: '' highlighted: '' selected: '' />
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
Author
Original author of the library:
Nadia Dillon
Modifications:
Andrey Efremov (gazedash)
Contributing
Pull requests are welcome!