@rntp/player 5.0.0-beta.5 → 5.0.0
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.
- package/ios/TrackPlayer.swift +1 -0
- package/ios/player/AVPlayerEngine.swift +1 -3
- package/ios/player/AudioPlayer.swift +36 -3
- package/lib/commonjs/interfaces/PlayerConfig.js.map +1 -1
- package/lib/module/interfaces/PlayerConfig.js.map +1 -1
- package/lib/typescript/src/interfaces/PlayerConfig.d.ts +3 -1
- package/lib/typescript/src/interfaces/PlayerConfig.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/interfaces/PlayerConfig.ts +3 -1
package/ios/TrackPlayer.swift
CHANGED
|
@@ -22,6 +22,7 @@ class AudioPlayer {
|
|
|
22
22
|
|
|
23
23
|
private let engine: PlayerEngine
|
|
24
24
|
private let queue = QueueManager()
|
|
25
|
+
private let cache: AudioCache?
|
|
25
26
|
private(set) var preloader: Preloader?
|
|
26
27
|
#if canImport(UIKit)
|
|
27
28
|
private let artworkCache = NSCache<NSString, UIImage>()
|
|
@@ -81,6 +82,7 @@ class AudioPlayer {
|
|
|
81
82
|
|
|
82
83
|
init(engine: PlayerEngine, cache: AudioCache? = nil, coordinator: DownloadCoordinator? = nil) {
|
|
83
84
|
self.engine = engine
|
|
85
|
+
self.cache = cache
|
|
84
86
|
if let cache = cache, let coordinator = coordinator {
|
|
85
87
|
self.preloader = Preloader(cache: cache, coordinator: coordinator)
|
|
86
88
|
}
|
|
@@ -89,7 +91,7 @@ class AudioPlayer {
|
|
|
89
91
|
if let engine = self.engine as? AVPlayerEngine,
|
|
90
92
|
engine.currentCacheKey == key {
|
|
91
93
|
DispatchQueue.main.async {
|
|
92
|
-
self.
|
|
94
|
+
self.triggerAutoPreloadIfNeeded()
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
}
|
|
@@ -175,6 +177,8 @@ class AudioPlayer {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
// MARK: - Queue: Load / Set
|
|
180
|
+
// Note: Any method that changes the queue or current item must call
|
|
181
|
+
// triggerAutoPreloadIfNeeded() so the preload window stays in sync.
|
|
178
182
|
|
|
179
183
|
func load(item: AudioItem) {
|
|
180
184
|
queue.replaceCurrentItem(with: item)
|
|
@@ -188,6 +192,7 @@ class AudioPlayer {
|
|
|
188
192
|
try? queue.jump(to: 0)
|
|
189
193
|
loadCurrentItem()
|
|
190
194
|
}
|
|
195
|
+
triggerAutoPreloadIfNeeded()
|
|
191
196
|
}
|
|
192
197
|
|
|
193
198
|
func add(items newItems: [AudioItem], at index: Int) throws {
|
|
@@ -197,6 +202,7 @@ class AudioPlayer {
|
|
|
197
202
|
try queue.jump(to: 0)
|
|
198
203
|
loadCurrentItem()
|
|
199
204
|
}
|
|
205
|
+
triggerAutoPreloadIfNeeded()
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
// MARK: - Queue: Navigate
|
|
@@ -243,6 +249,7 @@ class AudioPlayer {
|
|
|
243
249
|
}
|
|
244
250
|
} else {
|
|
245
251
|
try? queue.replaceItem(at: index, with: newItem)
|
|
252
|
+
triggerAutoPreloadIfNeeded()
|
|
246
253
|
}
|
|
247
254
|
}
|
|
248
255
|
|
|
@@ -269,6 +276,8 @@ class AudioPlayer {
|
|
|
269
276
|
state = .idle
|
|
270
277
|
clearNowPlayingInfo()
|
|
271
278
|
}
|
|
279
|
+
} else {
|
|
280
|
+
triggerAutoPreloadIfNeeded()
|
|
272
281
|
}
|
|
273
282
|
}
|
|
274
283
|
|
|
@@ -280,6 +289,14 @@ class AudioPlayer {
|
|
|
280
289
|
deactivateAudioSession()
|
|
281
290
|
}
|
|
282
291
|
|
|
292
|
+
/// Cancel all active downloads (preloads and in-progress streaming).
|
|
293
|
+
func cancelAllDownloads() {
|
|
294
|
+
preloader?.cancelAll()
|
|
295
|
+
if let engine = engine as? AVPlayerEngine {
|
|
296
|
+
engine.downloadCoordinator?.cancelAll()
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
283
300
|
// MARK: - Destroy
|
|
284
301
|
|
|
285
302
|
func destroy() {
|
|
@@ -328,11 +345,27 @@ class AudioPlayer {
|
|
|
328
345
|
state = .loading
|
|
329
346
|
updateNowPlayingMetadata(for: item)
|
|
330
347
|
onCurrentItemChanged?(item, queue.currentIndex)
|
|
348
|
+
triggerAutoPreloadIfNeeded()
|
|
331
349
|
}
|
|
332
350
|
|
|
333
|
-
///
|
|
334
|
-
|
|
351
|
+
/// Check if auto preloading should trigger and start it if so.
|
|
352
|
+
/// Preloads run when the current item is live, a local file, fully cached
|
|
353
|
+
/// on disk, or when the queue changes while one of those is already true.
|
|
354
|
+
private func triggerAutoPreloadIfNeeded() {
|
|
335
355
|
guard preloadWindow > 0, let preloader = preloader else { return }
|
|
356
|
+
|
|
357
|
+
let shouldPreload: Bool
|
|
358
|
+
if let current = queue.current, (current.isLive || current.sourceType == .file) {
|
|
359
|
+
shouldPreload = true
|
|
360
|
+
} else if let engine = engine as? AVPlayerEngine,
|
|
361
|
+
let key = engine.currentCacheKey,
|
|
362
|
+
let cache = cache, cache.isFullyCached(key: key) {
|
|
363
|
+
shouldPreload = true
|
|
364
|
+
} else {
|
|
365
|
+
shouldPreload = false
|
|
366
|
+
}
|
|
367
|
+
guard shouldPreload else { return }
|
|
368
|
+
|
|
336
369
|
preloader.cancelAll()
|
|
337
370
|
|
|
338
371
|
let startIndex = queue.currentIndex + 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_CONFIG","exports","maxSizeBytes","DEFAULT_CAST_RECEIVER_APP_ID","DEFAULT_ANDROID_PLAYER_CONFIG","wakeMode","skipSilenceEnabled","DEFAULT_PLAYER_CONFIG","contentType","handleAudioBecomingNoisy","android"],"sourceRoot":"../../../src","sources":["interfaces/PlayerConfig.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_CONFIG","exports","maxSizeBytes","DEFAULT_CAST_RECEIVER_APP_ID","DEFAULT_ANDROID_PLAYER_CONFIG","wakeMode","skipSilenceEnabled","DEFAULT_PLAYER_CONFIG","contentType","handleAudioBecomingNoisy","android"],"sourceRoot":"../../../src","sources":["interfaces/PlayerConfig.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;AAsCO,MAAMA,oBAA+D,GAAAC,OAAA,CAAAD,oBAAA,GAAG;EAC7EE,YAAY,EAAE,GAAG,GAAG,IAAI,GAAG;AAC7B,CAAC;;AAED;AACA;AACA;AACA;AACO,MAAMC,4BAA4B,GAAAF,OAAA,CAAAE,4BAAA,GAAG,UAAU;;AAEtD;AACO,MAAMC,6BAAkD,GAAAH,OAAA,CAAAG,6BAAA,GAAG;EAChEC,QAAQ,EAAE,MAAM;EAChBC,kBAAkB,EAAE;AACtB,CAAC;AAwBD;AACO,MAAMC,qBAIZ,GAAAN,OAAA,CAAAM,qBAAA,GAAG;EACFC,WAAW,EAAE,OAAO;EACpBC,wBAAwB,EAAE,IAAI;EAC9BC,OAAO,EAAEN;AACX,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_CONFIG","maxSizeBytes","DEFAULT_CAST_RECEIVER_APP_ID","DEFAULT_ANDROID_PLAYER_CONFIG","wakeMode","skipSilenceEnabled","DEFAULT_PLAYER_CONFIG","contentType","handleAudioBecomingNoisy","android"],"sourceRoot":"../../../src","sources":["interfaces/PlayerConfig.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_CONFIG","maxSizeBytes","DEFAULT_CAST_RECEIVER_APP_ID","DEFAULT_ANDROID_PLAYER_CONFIG","wakeMode","skipSilenceEnabled","DEFAULT_PLAYER_CONFIG","contentType","handleAudioBecomingNoisy","android"],"sourceRoot":"../../../src","sources":["interfaces/PlayerConfig.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAsCA,OAAO,MAAMA,oBAA+D,GAAG;EAC7EC,YAAY,EAAE,GAAG,GAAG,IAAI,GAAG;AAC7B,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,4BAA4B,GAAG,UAAU;;AAEtD;AACA,OAAO,MAAMC,6BAAkD,GAAG;EAChEC,QAAQ,EAAE,MAAM;EAChBC,kBAAkB,EAAE;AACtB,CAAC;AAwBD;AACA,OAAO,MAAMC,qBAIZ,GAAG;EACFC,WAAW,EAAE,OAAO;EACpBC,wBAAwB,EAAE,IAAI;EAC9BC,OAAO,EAAEN;AACX,CAAC","ignoreList":[]}
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
import type { PlayerCommand, RemoteControlHandling, PerCommandHandling } from './PlayerCommand';
|
|
6
6
|
export interface PreloadConfig {
|
|
7
7
|
/**
|
|
8
|
-
* Auto-preload next N tracks in queue
|
|
8
|
+
* Auto-preload next N tracks in queue. Preloading starts when the current
|
|
9
|
+
* item is live, a local file, or fully cached on disk. It also re-evaluates
|
|
10
|
+
* when the queue changes (items added, removed, replaced, or reordered).
|
|
9
11
|
* @default 0 (disabled)
|
|
10
12
|
*/
|
|
11
13
|
window?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlayerConfig.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/PlayerConfig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,aAAa;IAC5B
|
|
1
|
+
{"version":3,"file":"PlayerConfig.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/PlayerConfig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,EA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AAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CAC1D;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACjC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACxC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,9 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
export interface PreloadConfig {
|
|
13
13
|
/**
|
|
14
|
-
* Auto-preload next N tracks in queue
|
|
14
|
+
* Auto-preload next N tracks in queue. Preloading starts when the current
|
|
15
|
+
* item is live, a local file, or fully cached on disk. It also re-evaluates
|
|
16
|
+
* when the queue changes (items added, removed, replaced, or reordered).
|
|
15
17
|
* @default 0 (disabled)
|
|
16
18
|
*/
|
|
17
19
|
window?: number;
|