@javascriptcommon/react-native-track-player 4.1.16 → 4.1.17

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.
@@ -86,6 +86,10 @@ class Track: AudioItem, TimePitching, AssetOptionsProviding {
86
86
  func getAlbumTitle() -> String? {
87
87
  return album
88
88
  }
89
+
90
+ func getDuration() -> Double? {
91
+ return duration
92
+ }
89
93
 
90
94
  func getSourceType() -> SourceType {
91
95
  return url.isLocal ? .file : .stream
@@ -25,6 +25,7 @@ public protocol AudioItem {
25
25
  func getSourceUrl() -> String
26
26
  func getArtist() -> String?
27
27
  func getTitle() -> String?
28
+ func getDuration() -> Double?
28
29
  func getAlbumTitle() -> String?
29
30
  func getSourceType() -> SourceType
30
31
  func getArtwork(_ handler: @escaping (AudioItemImage?) -> Void)
@@ -57,6 +58,8 @@ public class DefaultAudioItem: AudioItem, Identifiable {
57
58
 
58
59
  public var albumTitle: String?
59
60
 
61
+ public var duration: Double?
62
+
60
63
  public var sourceType: SourceType
61
64
 
62
65
  public var artwork: AudioItemImage?
@@ -86,6 +89,10 @@ public class DefaultAudioItem: AudioItem, Identifiable {
86
89
  albumTitle
87
90
  }
88
91
 
92
+ public func getDuration() -> Double? {
93
+ duration
94
+ }
95
+
89
96
  public func getSourceType() -> SourceType {
90
97
  sourceType
91
98
  }
@@ -104,9 +104,12 @@ class AVPlayerItemObserver: NSObject {
104
104
  }
105
105
 
106
106
  case AVPlayerItemKeyPath.loadedTimeRanges:
107
- // Note: loadedTimeRanges represents buffered content, not total duration.
108
- // Do NOT call didUpdateDuration here - it would report buffer size instead of actual duration.
109
- break
107
+ if let item = observingItem, item.duration.isIndefinite || item.duration.seconds.isNaN,
108
+ let ranges = change?[.newKey] as? [NSValue],
109
+ let bufferDuration = ranges.first?.timeRangeValue.duration,
110
+ !bufferDuration.seconds.isNaN {
111
+ delegate?.item(didUpdateDuration: bufferDuration.seconds)
112
+ }
110
113
 
111
114
  case AVPlayerItemKeyPath.playbackLikelyToKeepUp:
112
115
  if let playbackLikelyToKeepUp = change?[.newKey] as? Bool {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@javascriptcommon/react-native-track-player",
3
- "version": "4.1.16",
3
+ "version": "4.1.17",
4
4
  "description": "A fully fledged audio module created for music apps",
5
5
  "main": "lib/src/index.js",
6
6
  "types": "lib/src/index.d.ts",