react-native-nitro-player 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,8 +30,7 @@ internal fun TrackPlayerCore.rebuildQueueAndPlayFromIndex(index: Int) {
30
30
 
31
31
  currentTrackIndex = index
32
32
  exo.clearMediaItems()
33
- exo.setMediaItems(mediaItems)
34
- exo.seekToDefaultPosition(0)
33
+ exo.setMediaItems(mediaItems, true)
35
34
  exo.prepare()
36
35
  }
37
36
 
@@ -123,7 +122,7 @@ internal fun TrackPlayerCore.updatePlayerQueue(tracks: List<TrackItem>) {
123
122
  val mediaId = if (playlistId.isNotEmpty()) "$playlistId:${track.id}" else track.id
124
123
  makeMediaItem(track, mediaId)
125
124
  }
126
- exo.setMediaItems(mediaItems, false)
125
+ exo.setMediaItems(mediaItems, true)
127
126
  if (exo.playbackState == Player.STATE_IDLE && mediaItems.isNotEmpty()) {
128
127
  exo.prepare()
129
128
  }
@@ -30,9 +30,13 @@ suspend fun TrackPlayerCore.loadPlaylist(
30
30
  }
31
31
 
32
32
  currentPlaylistId = playlistId
33
- updatePlayerQueue(playlist.tracks)
34
- if (targetIndex > 0) {
35
- playFromIndexInternal(targetIndex)
33
+ if (targetIndex == 0) {
34
+ updatePlayerQueue(playlist.tracks)
35
+ } else {
36
+ // Bypass updatePlayerQueue to avoid emitting a spurious onTrackChange for index 0.
37
+ // Set currentTracks directly so rebuildQueueAndPlayFromIndex can use them.
38
+ currentTracks = playlist.tracks
39
+ rebuildQueueAndPlayFromIndex(targetIndex)
36
40
  }
37
41
  checkUpcomingTracksForUrls(lookaheadCount)
38
42
  notifyTemporaryQueueChange()
@@ -156,6 +156,12 @@ extension TrackPlayerCore {
156
156
  && !DownloadManagerCore.shared.isTrackDownloaded(trackId: targetTrack.id)
157
157
  if isLazyLoad {
158
158
  NitroPlayerLogger.log("TrackPlayerCore", " ⏳ Lazy-load — deferring AVQueuePlayer setup; emitting track change for index \(index)")
159
+ // Clear old items immediately so the previous track stops while waiting for the URL to resolve
160
+ if let boundaryObserver = self.boundaryTimeObserver {
161
+ player?.removeTimeObserver(boundaryObserver)
162
+ self.boundaryTimeObserver = nil
163
+ }
164
+ player?.removeAllItems()
159
165
  self.currentTracks = fullPlaylist
160
166
  if let track = self.currentTracks[safe: index] {
161
167
  notifyTrackChange(track, .skip)
@@ -44,8 +44,13 @@ extension TrackPlayerCore {
44
44
  }
45
45
 
46
46
  self.currentPlaylistId = playlistId
47
- self.updatePlayerQueue(tracks: playlist.tracks)
48
- if targetIndex > 0 {
47
+ if targetIndex == 0 {
48
+ self.updatePlayerQueue(tracks: playlist.tracks)
49
+ } else {
50
+ // Bypass updatePlayerQueue to avoid emitting a spurious onTrackChange for index 0.
51
+ // Set currentTracks directly so rebuildQueueFromPlaylistIndex can use them.
52
+ self.currentTracks = playlist.tracks
53
+ self.preloadedAssets.removeAll()
49
54
  _ = self.rebuildQueueFromPlaylistIndex(index: targetIndex)
50
55
  }
51
56
  self.emitStateChange()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-player",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A powerful audio player library for React Native with playlist management, playback controls, and support for Android Auto and CarPlay",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",