react-native-mp3-player 1.0.7 → 1.0.9

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.
@@ -186,11 +186,11 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
186
186
  configureAudioSessionForBackgroundPlayback()
187
187
  configureAudioSession()
188
188
 
189
- // Enable remote control events as soon as the player is set up so the lock screen widget can appear on first track load.
189
+ // So the lock screen / Control Center widget can show as soon as nowPlayingInfo is set (first track add).
190
190
  if Thread.isMainThread {
191
191
  UIApplication.shared.beginReceivingRemoteControlEvents()
192
192
  } else {
193
- DispatchQueue.main.sync {
193
+ DispatchQueue.main.async {
194
194
  UIApplication.shared.beginReceivingRemoteControlEvents()
195
195
  }
196
196
  }
@@ -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
 
@@ -576,8 +590,8 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
576
590
  effectivePlaybackState = .playing
577
591
  player.play()
578
592
  updateNowPlayingPlaybackValuesOnMainIfNeeded()
579
- emit(event: EventType.PlaybackState, body: getPlaybackStateBodyKeyValues(state: .playing))
580
593
  resolve(NSNull())
594
+ emit(event: EventType.PlaybackState, body: getPlaybackStateBodyKeyValues(state: .playing))
581
595
  }
582
596
 
583
597
  @objc(pause:rejecter:)
@@ -586,8 +600,8 @@ public class RNTrackPlayer: NSObject, AudioSessionControllerDelegate {
586
600
  effectivePlaybackState = .paused
587
601
  player.pause()
588
602
  updateNowPlayingPlaybackValuesOnMainIfNeeded()
589
- emit(event: EventType.PlaybackState, body: getPlaybackStateBodyKeyValues(state: .paused))
590
603
  resolve(NSNull())
604
+ emit(event: EventType.PlaybackState, body: getPlaybackStateBodyKeyValues(state: .paused))
591
605
  }
592
606
 
593
607
  @objc(setPlayWhenReady:resolver:rejecter:)
@@ -215,14 +215,14 @@ public class AudioPlayer: AVPlayerWrapperDelegate {
215
215
  // (duration/elapsed/rate must be set; use 0 until the player reports real values).
216
216
  nowPlayingInfoController.set(keyValues: [
217
217
  MediaItemProperty.duration(0),
218
- NowPlayingInfoProperty.playbackRate((playWhenReady ?? self.playWhenReady) ? 1.0 : 0.0),
218
+ NowPlayingInfoProperty.playbackRate((playWhenReady ?? false) ? 1.0 : 0.0),
219
219
  NowPlayingInfoProperty.elapsedPlaybackTime(0)
220
220
  ])
221
221
  loadNowPlayingMetaValues()
222
- // Push to center synchronously on main so the lock screen widget appears immediately on first play.
222
+ // Flush to MPNowPlayingInfoCenter immediately on main so lock screen widget appears on first play
223
223
  nowPlayingInfoController.pushToCenterSync()
224
224
  }
225
-
225
+
226
226
  enableRemoteCommands(forItem: item)
227
227
 
228
228
  wrapper.load(
@@ -431,9 +431,6 @@ public class AudioPlayer: AVPlayerWrapperDelegate {
431
431
  }
432
432
 
433
433
  func AVWrapper(didUpdateDuration duration: Double) {
434
- if automaticallyUpdateNowPlayingInfo {
435
- nowPlayingInfoController.set(keyValue: MediaItemProperty.duration(duration))
436
- }
437
434
  event.updateDuration.emit(data: duration)
438
435
  }
439
436
 
@@ -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.7",
3
+ "version": "1.0.9",
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",