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

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.
@@ -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,9 @@ 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
+ // 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
110
110
 
111
111
  case AVPlayerItemKeyPath.playbackLikelyToKeepUp:
112
112
  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.16",
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",