Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-track-player

doublesymmetry129kApache-2.04.1.1TypeScript support: included

A fully fledged audio module created for music apps

react, react-native, track-player, audio-player, audio, player, music, controls, chromecast, android, ios, windows, hooks

readme

downloads npm discord Commitizen friendly


A fully-fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!

<picture> <source media="(prefers-color-scheme: dark)" srcset="https://www.runblaze.dev/logo_dark.png"> </picture>

Blaze sponsors RNTP by providing super fast Apple Silicon based macOS Github Action Runners. Use the discount code RNTP50 at checkout to get 50% off your first year.

Overview

Not sure where to start?

  1. Try Getting Started.
  2. Peruse the API Docs.
  3. Run the Example Project.

Commerical Usage

Are you using RNTP for a personal project? Great! Sponsor us if you're able but otherwise you can support us by reporting any bugs you find, sending us screenshots of your projects and starring us on Github 🌟

Are you using RNTP at your organisation and/or making money from it? Awesome! We rely on your support to keep RNTP developed and maintained under the Apache-2.0 license. You can do that through Github Sponsors.

Features

  • Lightweight - Optimized to use the least amount of resources according to your needs
  • Feels native - As everything is built together, it follows the same design principles as real music apps do
  • Multi-platform - Supports Android, iOS and Web
  • Media Controls support - Provides events for controlling the app from a Bluetooth device, the lock screen, 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
  • Adaptive bitrate streaming support - 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 in background
  • Fully Customizable - Even the notification icons are customizable!
  • Supports React Hooks 🎣 - Includes React Hooks for common use-cases so you don't have to write them

Why another music module?

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 they should be tied together can cause a lot of 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 the foreground (such as sound effects, voice messages, etc.)

react-native-music-controls is meant for apps using those audio modules, but it has a few problems: the audio isn't tied directly 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.

Example Setup

First please take a look at the Getting Started guide, but a basic example of how to play a track:

import TrackPlayer from 'react-native-track-player';

const start = async () => {
    // Set up the player
    await TrackPlayer.setupPlayer();

    // Add a track to the queue
    await TrackPlayer.add({
        id: 'trackId',
        url: require('track.mp3'),
        title: 'Track Title',
        artist: 'Track Artist',
        artwork: require('track.png')
    });

    // Start playing it
    await TrackPlayer.play();
};
start();

Core Team ✨


David Chavez

External Core Contributors ✨


Jacob Spizziri


Jonathan Puckey

Special Thanks ✨


Guilherme Chaguri


Dustin Bahr

Contributing

You want this package to be awesome and we want to deliver on that. As you know already you can just File A Ticket, but thats not actually the best way for you to get what you need (read on to see why). The best way is for you to Be A Champion and dive into the code.

File A Ticket

The reality is that filing a ticket isn't always enough. This is probably only going to work if your issue aligns with both the interests and the resources available to the core team. Here are the things that align with our interests in order of priority.

  1. Fixing widespread, common, and critical Bugs.
  2. Fixing uncommon but necessary Bugs.
  3. Introducing new Features that have broad value.

Now keep in mind available resources. Long story short, the thing you care about needs to be cared about by either a lot of other people, or by us.

BUT! There's another and, arguably even better way that helps you get what you need faster: Be A Champion.

Be A Champion

Being a champion makes it easy for us to help you. Which is what we all want! So how can you be a champion? Sponsor the Project or be willing to write some code.

If you're willing to write some code we're willing to:

  • Open a design discussion, give feedback, and approve something that works.
  • Provide guidance in the implementation journey.

So, in a nutshell, let us know you're willing to do the work and ask for a little guidance, and watch the things you care about get done faster than anyone else. The best help will be given to those who are willing to help themselves.

You don't have experience you say? It's OK!

You may be thinking that you can't help because you know nothing about native iOS or Android or maybe even React code. But we're willing to help guide you.

If you're up for that task then we can help you understand native code and how React Native works.

The only way you go from not-knowing to knowing is by learning. Learning isn't something you should be ashamed of nor is it something you should be scared of.

Where Do You Start?

Our goal is to make it as easy as possible for you to make changes to the library. All the documentation on how to work on the library and it's dependencies is located in this Guide

Release

The standard release command for this project is yarn version.

yarn version [--major | --minor | --patch | --new-version <version>]

Ex.

yarn version --new-version 1.2.17
yarn version --patch // 1.2.17 -> 1.2.18
yarn version --minor // 1.2.18 -> 1.3.0
yarn version --major // 2.0.0

This command will:

  1. Generate/update the Changelog
  2. Bump the package version
  3. Tag & pushing the commit
  4. Build & publish the package

Community

You can find us as part of the React Native Track Player:

  • #introduce-yourself - Come greet the newest members of this group!
  • #troubleshooting-forum - Ask members of the community to trouble shoot issues with your app and make recommendations.
  • #show-and-tell - Tell the community about the app you made with this project!
  • #news-and-releases - Stay updated about the latest releases and dev efforts on the project.

changelog

4.1.1 (2024-03-26)

  • RN: Fixes an issue when using local assets in release builds

4.1.0 (2024-03-25)

  • web: First beta version of RNTP for web
  • RN: Massively reduce npm package size
  • android: Fix: add namespace to support gradle 8
  • android: Improvement: add http headers to notification artwork request
  • android: Improvement: use http data source for local urls
  • android: Improvement: use SVGs for notification icons
  • android: Improvement: specify key when returning key error
  • ios: Improvement: improve internal use of playWhenReady to avoid issue where we'd load two tracks at once
  • ios: Fix: return correct already intialized error code
  • ios: Fix: avoid emitting empty common metadata
  • ios: Fix: occasional crash due to attaching metadata output
  • ios: Fix: sometimes progress bar would be broken after repeat

4.0.1 (2023-10-31)

  • android: Fix: notification dissapearing in background
  • android: Allow overriding notification channel name and description

4.0.0 (2023-10-20)

  • RN: New metadata events have a new metadata property that contains the metadata that was received
  • android: Fix: allow updating duration in notification metadata
  • ios: Avoid prematurely activating audio session
  • android: Fix: don't emit both PlaybackTrackChanged when queue ends (parity with iOS)
  • android: Fix: allow progressUpdateEventInterval to be set to a decimal value (partial seconds)
  • android: Support for setting grace period before stopForeground (defaults to 5 seconds)
  • ios: Fix: updating rate will immediately reflect in control center
  • android Fix: issue where loading a new track after end required seek to start
  • ios: Fix: crash adding output when load is called too fast

4.0.0-rc09 (2023-09-22)

  • RN: useIsPlaying hook now takes into account none state
  • ios: Fixes issue where rate was being reset to 1 on play
  • ios: Deactivates session before activating on play to avoid issues when losing focus in some scenarios
  • RN: Deprecated Event.PlaybackMetadataReceived and introduces three new events: [Event.AudioChapterMetadataReceived, Event.AudioTimedMetadataReceived, Event.AudioCommonMetadataReceived]
  • ios: Change default pitch algorithm to timeDomain instead of lowQualityZeroLatency
  • android: Fixes progress in notification for HLS audio

4.0.0-rc08 (2023-09-07)

  • RN: Undeprecate updateNowPlayingMetadata
  • android: Restore notification image caching
  • RN: Fix issue with updateOptions and local images
  • ios: Activate session on play to avoid issues with background audio
  • ios: Second fix for repeat mode
  • ios: Correctly update control center progress when pausing/playing

4.0.0-rc07 (2023-08-11)

  • ios: Fix firing of EventType.PlaybackQueueEnded (fixes #2038)
  • android: Avoid emitting track changed when replaying the same track
  • android: Fixed a regression where reset() wasn't clearing notification properly
  • android: Resolved a where the update metadata method was not working

4.0.0-rc06 (2023-07-25)

  • ios: Fix iOS not repeating track in RepeatMode.Track
  • RN: Improve types on asset types
  • android: Fix foreground issues and notification item
  • ios Fix race conditions in player property setting
  • android: Improve notification updates when spamming notification buttons
  • android Fix AudioPlayerState.IDLE when queue emptied
  • android Improve metadata handling

4.0.0-rc05 (2023-06-26)

  • ios: Fix crash on getting current item
  • android: Improve preciseness of seeking
  • android: Improve handling of service foregrounding

4.0.0-rc03 (2023-03-28)

  • android: Fixes compilation issue due to uses of Lifecycle (updates kotlin gradle plugin)

4.0.0-rc02 (2023-03-27)

Bug Fixes

  • android: Fix ANR crashes (#1974) (b70fbd7
  • android: Fix removeUpcomingItems (#67)
  • android: Notification fixes

  • ios: Fix removing items from queue other than the current track (#41)

  • ios: Fix player state not becoming paused after loading (#46)
  • ios: Fix current item not being updated when removing items from queue (#45)
  • ios: Avoid calling onSkippedToSameCurrentItem when track before is removed (#45)

4.0.0-rc01 (2023-03-14)

Bug Fixes

  • android: add deep link back (#1872) (9c227fa)
  • android: fix handling of seek capability (#1938) (166aa0d)
  • android: resolve problem with StopPlaybackAndRemoveNotification not working on subsequent exists (#1762) (e742959)
  • android: use “none” instead of “idle” for none state (#1924) (e125045)
  • clears queue on iOS when you call reset() (#1900) (e3c670a)
  • hooks: updates setting initial playback state in usePlaybackState hook (417f3c4), closes #1931
  • ios: emit state passed to handleAudioPlayerStateChange (#1928) (a65fdcd)
  • ios: prevents overwriting of forward/backward secs (#1855) (fb594c7), closes #1853

3.2.0 (2022-09-23)

Bug Fixes

  • android, events: properly intercept and fire remote playback events (#1668) (9ed308c)
  • android: fix state constants (#1751) (7215e64)
  • example, ios: remove Capability.Stop (#1671) (49800ab)
  • hooks: fix issues with excessive number of pending callbacks (#1686) (1b5bb02)
  • hooks: fix useTrackPlayerEvents dependencies (#1672) (f6229d6)
  • hooks: useProgress & usePlayback hooks (#1723) (31fa40a)
  • ios, events: fix an issue with PlaybackQueueEnded resulting from a race condition (#1750) (e938c68)
  • ios: fix various issues in iOS by upgrading SwiftAudioEx (#1738) (224c491)
  • ts: add null to getCurrentTrack return type (#1681) (096ec68)

Features

  • android: add back option to remove notification (#1730) (82a5df9)
  • android: add string values to State enum (#1734) (bd48c2d), closes #1688
  • android: default the behavior to handle audio becoming noisy (#1732) (dabf715)
  • ios: deprecate waitForBuffer (#1695) (d277182)
  • ios: improve disabling of playback-progress-updated (#1706) (57de8b5)

3.1.0 (18.08.22)

Enhancements
  • Uses latest KotlinAudio which does not use ExoPlayer fork.
  • Adds back support for bluetooth playback control.
Bug Fixes
  • Fixes crash with reset() on Android.
  • Removes destroy() on iOS - this was missed.
  • Removes the stop() method -- use pause() instead.

3.0.0 (11.08.22)

We are changing how the audio service handles its lifecycle. Previously we had the stopWithApp bool that would try and stop the service when you remove the app from recents, but due to how Android handles foreground services the OS never stops the app process, as it's waiting for the foreground service to come back. We are embracing this and going with what other audio apps (Spotify, Soundcloud, Google Podcast etc.) are doing.

Enhancements
  • Rewrite Android module in Kotlin and using KotlinAudio. [mpivchev](
Breaking
  • stopWithApp turns into stoppingAppPausesPlayback
  • destroy() is no longer available -
Bug Fixes
  • Fix crash with reset() on Android. dcvz

2.1.3 (30.03.22)

Enhancements
  • Add property isLiveStream to Track for correct display in iOS control center. dcvz

  • [iOS] Improve method documentation alpha0010

  • [Android] Add isServiceRunning method biomancer

Bug Fixes
  • [iOS] Fix track loop crash in certain cases mmmoussa

  • [iOS] Fix seek after play jspizziri

  • [Android] Support Android 12 devices abhaydee

  • [iOS] Add method resolves promise with index formula1

  • Fix getTrack return type puckey

  • [iOS] Fix ambient session not working grubicv

  • [Android] Android 12 and higher bug fix martin-richter-uk

  • [iOS] Update SwiftAudioEx to 0.14.6 to avoid LICENSE warning dcvz

  • Make react-native-windows and optional peer dependency (#1324). jspizziri

2.1.2 (25.10.21)

Enhancements
  • None.
Bug Fixes
  • Update SwiftAudioEx - Fixes issues with flickering notifications + pause between loads

  • Fix cyclic require warning regression #1057

  • [ios] Fix PlaybackQueueEnded event to be called only when the track ends #1243

2.1.1 (25.09.21)

Enhancements
  • [ios] Fix getCurrentTrack returns undefined instead of null
  • [ios] Fix getTrack returning undefined instead of nil
  • Fix an issue with next/previous in the control center stopping playing on iOS15
Bug Fixes
  • None.

2.1.0 (16.09.21)

Enhancements
  • None.
Bug Fixes
  • Remove Support for iOS 10 & Support Xcode 13 dcvz #1186

    • NOTE: Requires minimum deployment target to be updated to iOS 11.
  • Reset initialization on destroy sreten-bild

  • Fix onTaskRemoved NullPointerException Markario

2.0.3 (19.08.21)

Enhancements
  • None.
Bug Fixes
  • Fix Event.PlaybackQueueEnded firing on initialization on Android dcvz #1229

  • Make useProgress unmount aware. lyswhut

  • Make usePlaybackState unmount aware. dcvz

2.0.2 (15.08.21)

Enhancements
  • Import SwiftAudioEx through podspec dcvz
Bug Fixes
  • useProgress hook should update while paused dcvz

2.0.1 (11.08.21)

Enhancements
  • None.
Bug Fixes
  • Add startForeground to onCreate. Bang9 #620 #524 #473 #391

  • Fix compilation of Windows module. dcvz

  • Fix regression in updating artwork on updateMetadata and updateNowPlayingMetadata dcvz #662