An all-in-one module that provides audio playback, external media controls, chromecast support and background mode.
- Installation
- Getting Started
- Documentation
- Platform Support
- Cast Integration
- Car Integration
- Background Mode
- Build Preferences
- Lightweight - Optimized to use the least amount of resources according to your needs
- Media Controls support - Control the app from a bluetooth device, the lockscreen, a notification, a smartwatch or even a car
- Local or network, files or streams - It doesn't matter where the media belongs, we've got you covered
- Chromecast support - Seamlessly switch to any Google Cast compatible device, supporting custom media receivers
- Adaptive bitrate streaming support - Optional support for DASH, HLS or SmoothStreaming
- Caching support - Cache media files to play them again without an internet connection
- Background support - Keep playing audio even after the app is closed
- Fully Customizable - Even the notification icons are customizable!
Feature | Android | iOS | Windows |
---|---|---|---|
Load from the app bundle | ✓ | ✓ | ✓ |
Load from the network | ✓ | ✓ | ✓ |
Load from the file system | ✗ | ✗ | ✗ |
Adaptive Bitrate Streaming | ✓ | ✗ | ✓ |
Play/Pause/Stop/Reset | ✓ | ✓ | ✓ |
Seeking/Volume | ✓ | ✓ | ✓ |
Remote Media Controls | ✓ | ✓ | ✓ |
Caching | ✓ | ✗ | ✗ |
Events | ✓ | ✓ | ✓ |
Background Mode | ✓ | ✓ | ✓ |
Google Cast | ✓ | ✗ | ✗ |
Check Platform Support for more information.
After trying to team up modules like react-native-sound
, react-native-music-controls
and react-native-google-cast
, I've noticed that their structure and the way should be tied together can cause a lot problems (mainly on Android). Those can heavily affect the app stability and user experience.
All audio modules (like react-native-sound
) don't play in a separated service on Android, which should only be used for simple audio tracks in foreground (such as sound effects, voice messages, etc)
react-native-music-controls
is meant for apps using those audio modules, although it has a few problems due to how the audio is not directly tied to the controls, it can be pretty useful for casting (such as Chromecast)
react-native-google-cast
works pretty well and also supports custom receivers, but it has fewer player controls, it's harder to integrate and still uses the Cast SDK v2
If you want to get started with this module, check the API page. If you want detailed information about the API, check the Documentation.
import TrackPlayer from 'react-native-track-player';
// Creates the player
TrackPlayer.setupPlayer().then(() => {
// Adds a track to the queue
await TrackPlayer.add({
id: 'trackId',
url: require('track.mp3'),
title: 'Track Title',
artist: 'Track Artist',
artwork: require('track.png')
});
// Starts playing it
TrackPlayer.play();
});