@neoskola/auto-play 0.3.1 → 0.3.3

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.
@@ -57,7 +57,6 @@ class NowPlayingTemplate: AutoPlayTemplate {
57
57
 
58
58
  @MainActor
59
59
  func playAudio(url: String, startFrom: Double) -> Bool {
60
- // Clean up any existing player
61
60
  cleanupPlayer()
62
61
  completionFired = false
63
62
  lastReportedSecond = Int(startFrom)
@@ -67,9 +66,12 @@ class NowPlayingTemplate: AutoPlayTemplate {
67
66
  return false
68
67
  }
69
68
 
70
- // Ensure AVAudioSession is active
71
69
  NowPlayingSessionManager.shared.ensureSessionActive()
70
+ config.isPlaying = true
71
+ updateNowPlayingInfo()
72
+ MPNowPlayingInfoCenter.default().playbackState = .playing
72
73
 
74
+ // Direct AVPlayer streaming — URL now has correct headers from backend
73
75
  let asset = AVURLAsset(url: audioURL)
74
76
  playerItem = AVPlayerItem(asset: asset)
75
77
 
@@ -100,6 +102,8 @@ class NowPlayingTemplate: AutoPlayTemplate {
100
102
  player?.seek(to: time)
101
103
  }
102
104
 
105
+ player?.play()
106
+
103
107
  // Periodic time observer (every 1 second) for MPNowPlayingInfoCenter updates
104
108
  let interval = CMTime(seconds: 1.0, preferredTimescale: 600)
105
109
  timeObserver = player?.addPeriodicTimeObserver(
@@ -109,15 +113,6 @@ class NowPlayingTemplate: AutoPlayTemplate {
109
113
  self?.handleTimeUpdate(time: time)
110
114
  }
111
115
 
112
- // Playback finished notification
113
- didFinishObserver = NotificationCenter.default.addObserver(
114
- forName: .AVPlayerItemDidPlayToEndTime,
115
- object: playerItem,
116
- queue: .main
117
- ) { [weak self] _ in
118
- self?.handlePlaybackFinished()
119
- }
120
-
121
116
  // Progress report timer (every 30 seconds) — calls JS callback for backend reporting
122
117
  progressReportTimer = Timer.scheduledTimer(
123
118
  withTimeInterval: 30.0,
@@ -126,15 +121,16 @@ class NowPlayingTemplate: AutoPlayTemplate {
126
121
  self?.reportProgress()
127
122
  }
128
123
 
129
- // Play
130
- player?.play()
131
-
132
- // Update NowPlaying UI
133
- config.isPlaying = true
134
- updateNowPlayingInfo()
135
- MPNowPlayingInfoCenter.default().playbackState = .playing
124
+ // Playback finished notification
125
+ didFinishObserver = NotificationCenter.default.addObserver(
126
+ forName: .AVPlayerItemDidPlayToEndTime,
127
+ object: playerItem,
128
+ queue: .main
129
+ ) { [weak self] _ in
130
+ self?.handlePlaybackFinished()
131
+ }
136
132
 
137
- print("[NowPlayingTemplate] Native audio playback started: \(url)")
133
+ print("[NowPlayingTemplate] Streaming playback started: \(url)")
138
134
  return true
139
135
  }
140
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neoskola/auto-play",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",