Migrating from v3.2 to v4
General Additions
- New Function:
getActiveTrackIndex()
- Description: Gets the index of the current track, or
undefinedif no track loaded.
- New Function:
getProgress()
- Description: Returns progress, buffer and duration information.
- New Function:
getPlaybackState
- Description: Returns the current playback state.
- New Events:
Event.AudioChapterMetadataReceived,Event.AudioTimedMetadataReceived,Event.AudioCommonMetadataReceived
- Description: More detailed metadata events that are emitted when metadata is received from the native player.
General Changes
- The configuration option
alwaysPauseOnInterruptionhas been moved to theandroidsection of options.
await TrackPlayer.updateOptions({
+ android: {
+ alwaysPauseOnInterruption: true,
+ },
- alwaysPauseOnInterruption: true,
}
- On iOS, the pitch algorithm now defaults to
timeDomaininstead oflowQualityZeroLatency. The latter has been deprecated by Apple and has known issues on iOS 17.
Hook Behavior Updates
The usePlaybackState() hook now initially returns { state: undefined } before it has finished retrieving the current state. It previously returned State.None, indicating no track loaded.
Player Method Updates
- The
remove()function now supports removing the current track. If the current track is removed, the next track in the queue will be activated. If the current track was the last track in the queue, the first track will be activated.
The getTrack() function now returns undefined instead of null.
Player State Updates
- New player states have been introduced and some updated
- New. Emitted when an error state is encountered.
- New. State indicates playback stopped due to the end of the queue being reached.
- New. State indicating the initial loading phase of a track.
- Updated. Now emitted no matter whether playback is paused or not.
- Deprecated. Please use
State.Loadinginstead.
General Deprecations
- The following functions and events have been deprecated:
getState()- Please use thestateproperty returned bygetPlaybackState().getDuration()- Please use thedurationproperty returned bygetProgress().getPosition()- Please use thepositionproperty returned bygetProgress().getBufferedPosition()- Please use thebufferedproperty returned bygetProgress().getCurrentTrack()- Please usegetActiveTrackIndex().Event.PlaybackTrackChanged- Please useEvent.PlaybackActiveTrackChanged. Also note that in 4.0Event.PlaybackTrackChangedis no longer emitted when a track repeats.Event.PlaybackMetadataReceived- Please useEvent.AudioChapterMetadataReceived,Event.AudioTimedMetadataReceived,Event.AudioCommonMetadataReceived.
Removals
- The clearMetadata() function has been removed. Instead, use
reset(), which stops playback, clears the queue, and clears the notification.
Typescript Imports
- If you were using deep imports from RNTP, the
srchas been completely reorganized, and so you may need to adjust your imports accordingly. If you've been importing everything directly (ex.import ... from 'react-native-track-player';) then you don't need to do anything. - The
PlaybackStateEventinterface has been renamed toPlaybackState