react-native-nitro-player 0.7.1-alpha.3 → 1.0.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.
@@ -79,14 +79,16 @@ extension TrackPlayerCore {
79
79
  currentItem.status == .readyToPlay else { return }
80
80
 
81
81
  let duration = currentItem.duration.seconds
82
- guard duration > 0 && !duration.isNaN && !duration.isInfinite else { return }
83
-
84
82
  let interval: Double
85
- if duration > Constants.twoHoursInSeconds { interval = Constants.boundaryIntervalLong }
86
- else if duration > Constants.oneHourInSeconds { interval = Constants.boundaryIntervalMedium }
87
- else { interval = Constants.boundaryIntervalDefault }
83
+ if duration > 0 && !duration.isNaN && !duration.isInfinite {
84
+ if duration > Constants.twoHoursInSeconds { interval = Constants.boundaryIntervalLong }
85
+ else if duration > Constants.oneHourInSeconds { interval = Constants.boundaryIntervalMedium }
86
+ else { interval = Constants.boundaryIntervalDefault }
87
+ } else {
88
+ interval = Constants.boundaryIntervalDefault
89
+ }
88
90
 
89
- NitroPlayerLogger.log("TrackPlayerCore", "⏱️ Setting up periodic observer (interval: \(interval)s, duration: \(Int(duration))s)")
91
+ NitroPlayerLogger.log("TrackPlayerCore", "⏱️ Setting up periodic observer (interval: \(interval)s, duration: \(duration)s)")
90
92
 
91
93
  let cmInterval = CMTime(seconds: interval, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
92
94
  // Deliver on playerQueue (not main)
@@ -104,20 +106,23 @@ extension TrackPlayerCore {
104
106
  guard player.rate > 0 else { return }
105
107
 
106
108
  let position = currentItem.currentTime().seconds
107
- let duration = currentItem.duration.seconds
108
- guard duration > 0 && !duration.isNaN && !duration.isInfinite else { return }
109
+ let rawDuration = currentItem.duration.seconds
110
+ let duration = (rawDuration > 0 && !rawDuration.isNaN && !rawDuration.isInfinite) ? rawDuration : 0.0
109
111
 
110
- NitroPlayerLogger.log("TrackPlayerCore", "⏱️ Boundary crossed - position: \(Int(position))s / \(Int(duration))s")
112
+ NitroPlayerLogger.log("TrackPlayerCore", "⏱️ Boundary crossed - position: \(Int(position))s / duration: \(duration)s")
111
113
 
112
114
  notifyPlaybackProgress(position, duration, isManuallySeeked ? true : nil)
113
115
  isManuallySeeked = false
114
116
 
115
- let remaining = duration - position
116
- if remaining > 0 && remaining <= Constants.preferredForwardBufferDuration && !didRequestUrlsForCurrentItem {
117
- didRequestUrlsForCurrentItem = true
118
- NitroPlayerLogger.log("TrackPlayerCore",
119
- "⏳ \(Int(remaining))s remaining — proactively checking upcoming URLs")
120
- checkUpcomingTracksForUrls(lookahead: lookaheadCount)
117
+ // Only do remaining-time preload when duration is known
118
+ if duration > 0 {
119
+ let remaining = duration - position
120
+ if remaining > 0 && remaining <= Constants.preferredForwardBufferDuration && !didRequestUrlsForCurrentItem {
121
+ didRequestUrlsForCurrentItem = true
122
+ NitroPlayerLogger.log("TrackPlayerCore",
123
+ "⏳ \(Int(remaining))s remaining — proactively checking upcoming URLs")
124
+ checkUpcomingTracksForUrls(lookahead: lookaheadCount)
125
+ }
121
126
  }
122
127
  }
123
128
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  import AVFoundation
9
9
  import Foundation
10
+ import MediaPlayer
10
11
 
11
12
  extension TrackPlayerCore {
12
13
 
@@ -115,8 +116,15 @@ extension TrackPlayerCore {
115
116
  self.isManuallySeeked = true
116
117
  let time = CMTime(seconds: position, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
117
118
  player.seek(to: time) { [weak self] completed in
118
- // Update now playing info to restore playback rate after seek
119
- DispatchQueue.main.async { self?.mediaSessionManager?.refresh() }
119
+ // HackFix I dont know how to fix this, but it works.
120
+ let rate = Double(player.rate)
121
+ DispatchQueue.main.async {
122
+ if var info = MPNowPlayingInfoCenter.default().nowPlayingInfo {
123
+ info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = position
124
+ info[MPNowPlayingInfoPropertyPlaybackRate] = rate
125
+ MPNowPlayingInfoCenter.default().nowPlayingInfo = info
126
+ }
127
+ }
120
128
  if completed {
121
129
  let duration = player.currentItem?.duration.seconds ?? 0.0
122
130
  self?.notifySeek(position, duration)
@@ -43,7 +43,8 @@ extension TrackPlayerCore {
43
43
  }
44
44
  let currentTrack = getCurrentTrack()
45
45
  let currentPosition = player.currentTime().seconds
46
- let totalDuration = player.currentItem?.duration.seconds ?? 0.0
46
+ let rawDuration = player.currentItem?.duration.seconds ?? 0.0
47
+ let totalDuration = (rawDuration > 0 && !rawDuration.isNaN && !rawDuration.isInfinite) ? rawDuration : 0.0
47
48
 
48
49
  let state: TrackPlayerState
49
50
  if player.rate == 0 { state = .paused }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-player",
3
- "version": "0.7.1-alpha.3",
3
+ "version": "1.0.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",