@javascriptcommon/react-native-track-player 4.1.15 → 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
  }
@@ -214,7 +214,7 @@ public class AudioPlayer: AVPlayerWrapperDelegate {
214
214
  // Reset playback values without updating, because that will happen in
215
215
  // the loadNowPlayingMetaValues call straight after:
216
216
  nowPlayingInfoController.setWithoutUpdate(keyValues: [
217
- MediaItemProperty.duration(nil),
217
+ MediaItemProperty.duration(item.getDuration()),
218
218
  NowPlayingInfoProperty.playbackRate(nil),
219
219
  NowPlayingInfoProperty.elapsedPlaybackTime(nil)
220
220
  ])
@@ -328,6 +328,7 @@ public class AudioPlayer: AVPlayerWrapperDelegate {
328
328
  MediaItemProperty.artist(item.getArtist()),
329
329
  MediaItemProperty.title(item.getTitle()),
330
330
  MediaItemProperty.albumTitle(item.getAlbumTitle()),
331
+ MediaItemProperty.duration(item.getDuration()),
331
332
  ])
332
333
  loadArtwork(forItem: item)
333
334
  }
@@ -341,8 +342,10 @@ public class AudioPlayer: AVPlayerWrapperDelegate {
341
342
  - Playback rate
342
343
  */
343
344
  func updateNowPlayingPlaybackValues() {
345
+ // Use wrapper.duration if valid, otherwise fallback to currentItem's duration (from metadata)
346
+ let duration = wrapper.duration > 0 ? wrapper.duration : (currentItem?.getDuration() ?? 0)
344
347
  nowPlayingInfoController.set(keyValues: [
345
- MediaItemProperty.duration(wrapper.duration),
348
+ MediaItemProperty.duration(duration),
346
349
  NowPlayingInfoProperty.playbackRate(wrapper.playWhenReady ? Double(wrapper.rate) : 0),
347
350
  NowPlayingInfoProperty.elapsedPlaybackTime(wrapper.currentTime)
348
351
  ])
@@ -422,6 +425,9 @@ public class AudioPlayer: AVPlayerWrapperDelegate {
422
425
 
423
426
  func AVWrapper(didUpdateDuration duration: Double) {
424
427
  event.updateDuration.emit(data: duration)
428
+ /*if(automaticallyUpdateNowPlayingInfo){
429
+ updateNowPlayingPlaybackValues()
430
+ }*/
425
431
  }
426
432
 
427
433
  func AVWrapper(didReceiveCommonMetadata metadata: [AVMetadataItem]) {
@@ -104,9 +104,12 @@ class AVPlayerItemObserver: NSObject {
104
104
  }
105
105
 
106
106
  case AVPlayerItemKeyPath.loadedTimeRanges:
107
- if let ranges = change?[.newKey] as? [NSValue], let duration = ranges.first?.timeRangeValue.duration {
108
- delegate?.item(didUpdateDuration: duration.seconds)
109
- }
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.15",
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",