react-native-mp3-player 1.0.8 → 1.0.10

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.
@@ -374,6 +374,15 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
374
374
  forwardJumpInterval = options["forwardJumpInterval"] as? NSNumber ?? forwardJumpInterval
375
375
  backwardJumpInterval = options["backwardJumpInterval"] as? NSNumber ?? backwardJumpInterval
376
376
 
377
+ // When jump intervals are set, prefer 15s rewind/forward as the main transport buttons (left/right)
378
+ // by not registering next/previous with MPRemoteCommandCenter. Only skipForward/skipBackward are used,
379
+ // so the lock screen shows "15 second rewind" on the left and "15 second forward" on the right.
380
+ let fwd = (forwardJumpInterval?.doubleValue ?? 0)
381
+ let bwd = (backwardJumpInterval?.doubleValue ?? 0)
382
+ if fwd > 0 && bwd > 0 {
383
+ capabilitiesStr = capabilitiesStr.filter { $0 != "next" && $0 != "previous" }
384
+ }
385
+
377
386
  player.remoteCommands = capabilitiesStr
378
387
  .compactMap { Capability(rawValue: $0) }
379
388
  .map { capability in
@@ -390,6 +399,11 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
390
399
  progressUpdateEventIntervalSeconds = interval
391
400
  configureProgressUpdateEvent(interval: interval)
392
401
 
402
+ // Ensure Now Playing widget is visible after options change (e.g. capabilities without next/previous).
403
+ if player.currentItem != nil && player.automaticallyUpdateNowPlayingInfo {
404
+ player.nowPlayingInfoController.pushToCenterSync()
405
+ }
406
+
393
407
  resolve(NSNull())
394
408
  }
395
409
 
@@ -868,6 +882,9 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
868
882
  switch state {
869
883
  case .ready, .playing, .paused:
870
884
  if player.currentItem != nil && player.automaticallyUpdateNowPlayingInfo {
885
+ // Force push so the widget appears immediately (avoids "Not Playing" / blank artwork).
886
+ player.loadNowPlayingMetaValues()
887
+ player.nowPlayingInfoController.pushToCenterSync()
871
888
  let useProgressTickForNowPlaying = shouldEmitProgressEvent && progressUpdateEventIntervalSeconds > 0 && progressUpdateEventIntervalSeconds <= 1.0
872
889
  if !useProgressTickForNowPlaying {
873
890
  scheduleNextNowPlayingUpdate()
@@ -897,9 +914,12 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
897
914
  }
898
915
 
899
916
  /// Updates MPNowPlayingInfoCenter (rate, elapsed, duration) synchronously so the widget reflects play/pause before we return to JS. Call after play()/pause() from JS or remote.
917
+ /// Also refreshes title/artist/artwork so the widget never shows "Not Playing" or blank when a track is loaded.
900
918
  private func updateNowPlayingPlaybackValuesOnMainIfNeeded() {
901
919
  guard player.currentItem != nil, player.automaticallyUpdateNowPlayingInfo else { return }
920
+ player.loadNowPlayingMetaValues()
902
921
  player.updateNowPlayingPlaybackValuesSync()
922
+ player.nowPlayingInfoController.pushToCenterSync()
903
923
  }
904
924
 
905
925
  func handleAudioPlayerCommonMetadataReceived(metadata: [AVMetadataItem]) {
@@ -939,10 +959,12 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
939
959
  DispatchQueue.main.async {
940
960
  UIApplication.shared.beginReceivingRemoteControlEvents();
941
961
  }
942
- // Update now playing controller with isLiveStream option from track
962
+ // Update now playing controller with isLiveStream option from track and push so widget shows new track (e.g. after close and play again).
943
963
  if self.player.automaticallyUpdateNowPlayingInfo {
944
964
  let isTrackLiveStream = (item as? Track)?.isLiveStream ?? false
945
965
  self.player.nowPlayingInfoController.set(keyValue: NowPlayingInfoProperty.isLiveStream(isTrackLiveStream))
966
+ self.player.loadNowPlayingMetaValues()
967
+ self.player.nowPlayingInfoController.pushToCenterSync()
946
968
  }
947
969
  } else {
948
970
  DispatchQueue.main.async {
@@ -7,6 +7,9 @@
7
7
 
8
8
  import Foundation
9
9
  import MediaPlayer
10
+ #if canImport(UIKit)
11
+ import UIKit
12
+ #endif
10
13
 
11
14
  public class NowPlayingInfoController: NowPlayingInfoControllerProtocol {
12
15
  private let lock = NSLock()
@@ -75,14 +78,21 @@ public class NowPlayingInfoController: NowPlayingInfoControllerProtocol {
75
78
  }
76
79
 
77
80
  /// Push the current info dictionary to MPNowPlayingInfoCenter synchronously on main so the lock screen widget appears immediately.
81
+ /// Ensures remote control events are enabled before setting info so the lock screen works on first play (not only after stop → play again).
78
82
  public func pushToCenterSync() {
79
83
  lock.lock()
80
84
  let snapshot = self.info
81
85
  lock.unlock()
82
86
  if Thread.isMainThread {
87
+ #if canImport(UIKit)
88
+ UIApplication.shared.beginReceivingRemoteControlEvents()
89
+ #endif
83
90
  infoCenter.nowPlayingInfo = snapshot
84
91
  } else {
85
92
  DispatchQueue.main.sync { [weak self] in
93
+ #if canImport(UIKit)
94
+ UIApplication.shared.beginReceivingRemoteControlEvents()
95
+ #endif
86
96
  self?.infoCenter.nowPlayingInfo = snapshot
87
97
  }
88
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mp3-player",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "React Native audio player with reliable iOS background playback. Media controls, queue, hooks. Built for stability and long-running playback.",
5
5
  "main": "lib/src/index.js",
6
6
  "types": "lib/src/index.d.ts",