react-native-queue-player 1.0.3 → 1.0.4
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/android/src/main/java/com/margelo/nitro/queueplayer/BufferStateTranslator.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/CarConnectionState.kt +46 -0
- package/android/src/main/java/com/margelo/nitro/queueplayer/Equalizer.kt +1 -3
- package/android/src/main/java/com/margelo/nitro/queueplayer/HeadlessJsMediaService.kt +2 -4
- package/android/src/main/java/com/margelo/nitro/queueplayer/LookaheadCacheWriter.kt +7 -9
- package/android/src/main/java/com/margelo/nitro/queueplayer/MilestoneTracker.kt +1 -2
- package/android/src/main/java/com/margelo/nitro/queueplayer/PlaybackService.kt +5 -6
- package/android/src/main/java/com/margelo/nitro/queueplayer/PlaybackServiceCallback.kt +8 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/ProgressEmissionGate.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/QueueMutationArithmetic.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/QueueSkipArithmetic.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/RemoteCommandDeduper.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/SleepTimerCore.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/queueplayer/TrackPlayer.kt +21 -27
- package/android/src/main/java/com/margelo/nitro/queueplayer/TransportStateTranslator.kt +2 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/AudioPipelineRenderersFactoryTest.kt +2 -5
- package/android/src/test/java/com/margelo/nitro/queueplayer/BrowseCallbackRegistryTest.kt +1 -4
- package/android/src/test/java/com/margelo/nitro/queueplayer/CrossfadeEngineLifecycleTest.kt +1 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/CrossfadeEngineReplayGainTest.kt +3 -7
- package/android/src/test/java/com/margelo/nitro/queueplayer/EqualizerEngineTest.kt +1 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/EqualizerKtTest.kt +1 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/EqualizerLegacyEngineTest.kt +2 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/FFTProcessorTeeTest.kt +1 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/GaplessEngineLifecycleTest.kt +0 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/GaplessEngineReplayGainTest.kt +3 -8
- package/android/src/test/java/com/margelo/nitro/queueplayer/HeadlessJsMediaServiceTest.kt +2 -4
- package/android/src/test/java/com/margelo/nitro/queueplayer/MediaItemBuilderTest.kt +2 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/MilestoneTrackerTest.kt +1 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/NowPlayingFormatExtractorTest.kt +1 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/PitchAwareAudioProcessorChainTest.kt +1 -1
- package/android/src/test/java/com/margelo/nitro/queueplayer/PitchCorrectionTest.kt +2 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/PlaybackServiceCallbackTest.kt +76 -7
- package/android/src/test/java/com/margelo/nitro/queueplayer/ProgressEmissionGateTest.kt +1 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerEventsTest.kt +1 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerMutationTest.kt +2 -4
- package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerPitchCorrectionTest.kt +1 -2
- package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerPlaybackModeTest.kt +2 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerReplayGainTest.kt +1 -3
- package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerTransportTest.kt +2 -5
- package/android/src/test/java/com/margelo/nitro/queueplayer/VisualizerKtTest.kt +1 -2
- package/ios/AVPlayerItemQueueItemId.swift +2 -2
- package/ios/AVQueueBuilder.swift +12 -14
- package/ios/CarPlayCoordinator.swift +28 -0
- package/ios/CarPlaySceneDelegate.swift +2 -0
- package/ios/CrossfadeEngine.swift +4 -5
- package/ios/InputGuards.swift +3 -3
- package/ios/LookaheadCache.swift +4 -6
- package/ios/LookaheadCachePrefetcher.swift +1 -1
- package/ios/MilestoneTracker.swift +1 -2
- package/ios/PlaybackErrorMapping.swift +6 -7
- package/ios/PlayerStateDerivation.swift +1 -2
- package/ios/ProgressEmissionGate.swift +1 -1
- package/ios/QueueMutationArithmetic.swift +2 -2
- package/ios/QueueSkipArithmetic.swift +8 -12
- package/ios/Siri/PlayMediaIntentHandler.swift +1 -5
- package/ios/SleepTimerCore.swift +1 -1
- package/ios/Tests/AudioTapProviderReplayGainTests.swift +5 -9
- package/ios/Tests/CarPlayBridgeTests.swift +2 -6
- package/ios/Tests/CarPlayBrowseBuilderTests.swift +1 -2
- package/ios/Tests/CarPlayCoordinatorTests.swift +35 -0
- package/ios/Tests/EQProcessorTests.swift +1 -4
- package/ios/Tests/EQTapTests.swift +1 -2
- package/ios/Tests/EqualizerAudioMixProviderTests.swift +3 -4
- package/ios/Tests/EqualizerHybridTests.swift +1 -3
- package/ios/Tests/FFTProcessorTests.swift +1 -3
- package/ios/Tests/GaplessEngineLifecycleTests.swift +0 -2
- package/ios/Tests/LookaheadCacheEvictionTests.swift +1 -4
- package/ios/Tests/MetadataReaderTests.swift +0 -2
- package/ios/Tests/MilestoneTrackerTests.swift +1 -3
- package/ios/Tests/NowPlayingFormatExtractorTests.swift +3 -4
- package/ios/Tests/PlaybackErrorMappingTests.swift +0 -3
- package/ios/Tests/PlaybackModeStateMachineTests.swift +5 -9
- package/ios/Tests/PlayerStateDerivationTests.swift +1 -2
- package/ios/Tests/ProgressEmissionGateTests.swift +1 -3
- package/ios/Tests/QueueMutationArithmeticTests.swift +0 -3
- package/ios/Tests/RemoteCommandsTests.swift +2 -5
- package/ios/Tests/ReplayGainExtractorTests.swift +0 -5
- package/ios/Tests/SkipCapabilityTests.swift +4 -7
- package/ios/Tests/VoiceDonationTests.swift +4 -4
- package/ios/TrackPlayer.swift +5 -2
- package/lib/typescript/TrackPlayer.nitro.d.ts +17 -0
- package/lib/typescript/TrackPlayer.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.cpp +5 -0
- package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/queueplayer/HybridTrackPlayerSpec.kt +4 -0
- package/nitrogen/generated/ios/c++/HybridTrackPlayerSpecSwift.hpp +8 -0
- package/nitrogen/generated/ios/swift/HybridTrackPlayerSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridTrackPlayerSpec_cxx.swift +12 -0
- package/nitrogen/generated/shared/c++/HybridTrackPlayerSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridTrackPlayerSpec.hpp +1 -0
- package/package.json +1 -1
- package/src/TrackPlayer.nitro.ts +18 -0
|
@@ -9,7 +9,7 @@ import androidx.media3.common.Player
|
|
|
9
9
|
*
|
|
10
10
|
* Extracted from [TrackPlayer.computeBufferState] so the discriminator
|
|
11
11
|
* between an initial `BUFFERING` load and a mid-playback `STALLED`
|
|
12
|
-
* rebuffer
|
|
12
|
+
* rebuffer stands alone without a live ExoPlayer, matching the
|
|
13
13
|
* [TransportStateTranslator] pattern.
|
|
14
14
|
*/
|
|
15
15
|
internal object BufferStateTranslator {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package com.margelo.nitro.queueplayer
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.VisibleForTesting
|
|
4
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Process-wide count of attached headless (automotive) controllers, backing
|
|
8
|
+
* the `isCarConnected()` getter. Holds the same "a car is connected" state
|
|
9
|
+
* the `onCarConnect` / `onCarDisconnect` events transition between, so a
|
|
10
|
+
* consumer that missed the connect event — because it fired before the
|
|
11
|
+
* consumer registered its handler in this process — can still gate car-only
|
|
12
|
+
* work (e.g. browse-snapshot pushes) on the current connection.
|
|
13
|
+
*
|
|
14
|
+
* The count is process-scoped rather than tied to a [PlaybackService]
|
|
15
|
+
* instance so it stays correct across a service restart while a controller
|
|
16
|
+
* remains attached: the new instance's `onConnect` and the dying instance's
|
|
17
|
+
* late `onConnect`/`onDisconnected` all mutate this single source of truth, so
|
|
18
|
+
* the getter can't momentarily read disconnected mid-handoff. It is
|
|
19
|
+
* floor-guarded so a stray disconnect can't drive it negative, and process
|
|
20
|
+
* death clears it (a fresh process starts disconnected), which is correct.
|
|
21
|
+
*
|
|
22
|
+
* Only [PlaybackServiceCallback] mutates this — at the same headless
|
|
23
|
+
* connect / disconnect points that drive the events. This count is separate
|
|
24
|
+
* from that callback's per-instance counter, which stays per-service so the
|
|
25
|
+
* events keep their per-session first/last edge semantics.
|
|
26
|
+
*/
|
|
27
|
+
internal object CarConnectionState {
|
|
28
|
+
private val count = AtomicInteger(0)
|
|
29
|
+
|
|
30
|
+
fun isConnected(): Boolean = count.get() > 0
|
|
31
|
+
|
|
32
|
+
/** A headless controller attached. */
|
|
33
|
+
fun retain() {
|
|
34
|
+
count.incrementAndGet()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A headless controller detached; never drops below zero. */
|
|
38
|
+
fun release() {
|
|
39
|
+
count.updateAndGet { if (it > 0) it - 1 else 0 }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@VisibleForTesting
|
|
43
|
+
fun reset() {
|
|
44
|
+
count.set(0)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -25,9 +25,7 @@ import com.margelo.nitro.core.Promise
|
|
|
25
25
|
* The JS-facing methods that mutate state return `Promise<Unit>`
|
|
26
26
|
* via `Promise.async` per the spec, but each delegates to a
|
|
27
27
|
* synchronous `*Internal` method that owns the actual mutation.
|
|
28
|
-
*
|
|
29
|
-
* JS-interface adapter and is exercised at integration via demo
|
|
30
|
-
* Maestro.
|
|
28
|
+
* The async wrapper is a thin JS-interface adapter.
|
|
31
29
|
*
|
|
32
30
|
* Listener registries follow the same shape as other event
|
|
33
31
|
* listeners on this lib: stable numeric IDs returned via the
|
|
@@ -141,8 +141,7 @@ public abstract class HeadlessJsMediaService :
|
|
|
141
141
|
/**
|
|
142
142
|
* The host's [ReactHost]. Returns `null` when the host
|
|
143
143
|
* `Application` does not implement [ReactApplication] — production
|
|
144
|
-
* Expo / RN consumers always do
|
|
145
|
-
* Robolectric / unit-test path where the application is a stub.
|
|
144
|
+
* Expo / RN consumers always do.
|
|
146
145
|
*/
|
|
147
146
|
protected val reactHost: ReactHost?
|
|
148
147
|
get() = (application as? ReactApplication)?.reactHost
|
|
@@ -151,8 +150,7 @@ public abstract class HeadlessJsMediaService :
|
|
|
151
150
|
* The live [ReactContext] from the consumer app's [ReactHost], or
|
|
152
151
|
* `null` when no context has been created yet (the service kicks
|
|
153
152
|
* one off via [createReactContextAndScheduleTask] in that case) OR
|
|
154
|
-
* when the host application isn't a [ReactApplication] at all
|
|
155
|
-
* unit-test stubs).
|
|
153
|
+
* when the host application isn't a [ReactApplication] at all.
|
|
156
154
|
*/
|
|
157
155
|
protected val reactContext: ReactContext?
|
|
158
156
|
get() = reactHost?.currentReactContext
|
|
@@ -285,9 +285,8 @@ class LookaheadCacheWriter @VisibleForTesting internal constructor(
|
|
|
285
285
|
* cache state.
|
|
286
286
|
*
|
|
287
287
|
* `runCatching` swallows the "Method myLooper in android.os.Looper
|
|
288
|
-
* not mocked" exception that fires
|
|
289
|
-
*
|
|
290
|
-
* fast); production reads the looper normally.
|
|
288
|
+
* not mocked" exception that fires on a JVM host without the Android
|
|
289
|
+
* framework present; production reads the looper normally.
|
|
291
290
|
*/
|
|
292
291
|
private fun requireMainThread() {
|
|
293
292
|
val onMain = runCatching {
|
|
@@ -429,12 +428,11 @@ class LookaheadCacheWriter @VisibleForTesting internal constructor(
|
|
|
429
428
|
// Errors (OutOfMemoryError etc.) propagate — those are
|
|
430
429
|
// not transient and shouldn't be hidden.
|
|
431
430
|
//
|
|
432
|
-
// Log via runCatching:
|
|
433
|
-
//
|
|
434
|
-
//
|
|
435
|
-
//
|
|
436
|
-
//
|
|
437
|
-
// log normally; tests get a silent no-op.
|
|
431
|
+
// Log via runCatching: on a JVM host without the Android
|
|
432
|
+
// framework present, android.util.Log is not stubbed, so a
|
|
433
|
+
// Log.w call would throw "Method w in android.util.Log not
|
|
434
|
+
// mocked" and terminate the prefetch loop. Production reads
|
|
435
|
+
// this log normally.
|
|
438
436
|
runCatching { Log.w(TAG, "Lookahead prefetch failed for ${track.url}: ${e.message}") }
|
|
439
437
|
}
|
|
440
438
|
|
|
@@ -2,8 +2,7 @@ package com.margelo.nitro.queueplayer
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Tracks fixed playback-progress milestones (25/50/75/90%) for the
|
|
5
|
-
* current track playthrough. Pure + deterministic (no Media3)
|
|
6
|
-
* unit-tests directly.
|
|
5
|
+
* current track playthrough. Pure + deterministic (no Media3).
|
|
7
6
|
*
|
|
8
7
|
* A threshold emits only when forward playback crosses it: [seek] moves
|
|
9
8
|
* the baseline WITHOUT emitting (so thresholds a seek jumps over are
|
|
@@ -150,8 +150,8 @@ class PlaybackService : HeadlessJsMediaService() {
|
|
|
150
150
|
* [PendingIntentBuffer] TTL: ~3 s for bridge boot + ~17 s of
|
|
151
151
|
* headroom for the consumer's network calls before the controller
|
|
152
152
|
* surfaces "no results" and the user retries. The two platforms'
|
|
153
|
-
* cold-start windows are deliberately the same so the
|
|
154
|
-
*
|
|
153
|
+
* cold-start windows are deliberately kept the same so the
|
|
154
|
+
* behaviour is identical on iPhone + Android.
|
|
155
155
|
*/
|
|
156
156
|
private const val HEADLESS_DISPATCH_TIMEOUT_MS = 20_000L
|
|
157
157
|
|
|
@@ -1455,10 +1455,9 @@ class PlaybackService : HeadlessJsMediaService() {
|
|
|
1455
1455
|
override fun getTaskConfig(intent: Intent?): com.facebook.react.jstasks.HeadlessJsTaskConfig? {
|
|
1456
1456
|
val action = intent?.action ?: return null
|
|
1457
1457
|
if (action !in HEADLESS_WAKE_ACTIONS) return null
|
|
1458
|
-
//
|
|
1459
|
-
//
|
|
1460
|
-
//
|
|
1461
|
-
// classpath.
|
|
1458
|
+
// Non-ReactApplication hosts cannot spawn a JS task —
|
|
1459
|
+
// short-circuit here so `Arguments.createMap()` never has to load
|
|
1460
|
+
// the React native libs such a host lacks.
|
|
1462
1461
|
if ((application as? com.facebook.react.ReactApplication) == null) return null
|
|
1463
1462
|
// Belt-and-braces: if a wake intent somehow lands while a React
|
|
1464
1463
|
// context is already alive (foreground app, prior wake already
|
|
@@ -73,7 +73,7 @@ internal class PlaybackServiceCallback(
|
|
|
73
73
|
* package (Android Auto, Wear OS, Google Assistant) connects.
|
|
74
74
|
* Production wires the React-context cold-start through here so
|
|
75
75
|
* "Hey Google, play …" works from a phone with the app killed.
|
|
76
|
-
* Default no-op so
|
|
76
|
+
* Default no-op so callers without a wired service fall
|
|
77
77
|
* through harmlessly. */
|
|
78
78
|
fun onHeadlessControllerConnect(packageName: String) {}
|
|
79
79
|
|
|
@@ -287,6 +287,9 @@ internal class PlaybackServiceCallback(
|
|
|
287
287
|
): MediaSession.ConnectionResult {
|
|
288
288
|
if (controller.packageName in HEADLESS_ELIGIBLE_PACKAGES) {
|
|
289
289
|
val previousCount = headlessControllerCount.getAndIncrement()
|
|
290
|
+
// A headless controller is now attached — record it in the process-wide
|
|
291
|
+
// count the `isCarConnected()` getter reads.
|
|
292
|
+
CarConnectionState.retain()
|
|
290
293
|
environment.onHeadlessControllerConnect(controller.packageName)
|
|
291
294
|
// Fire onCarConnect only on the FIRST headless controller of
|
|
292
295
|
// this service-lifetime session — subsequent connects (Wear
|
|
@@ -348,6 +351,10 @@ internal class PlaybackServiceCallback(
|
|
|
348
351
|
} else if (previousCount > 0 && remaining == 0) {
|
|
349
352
|
environment.onHeadlessControllerDisconnect()
|
|
350
353
|
}
|
|
354
|
+
// Drop this controller from the process-wide connection count the
|
|
355
|
+
// `isCarConnected()` getter reads (floor-guarded against a stray
|
|
356
|
+
// disconnect, so it can't go negative).
|
|
357
|
+
CarConnectionState.release()
|
|
351
358
|
}
|
|
352
359
|
super.onDisconnected(session, controller)
|
|
353
360
|
}
|
|
@@ -3,7 +3,7 @@ package com.margelo.nitro.queueplayer
|
|
|
3
3
|
/**
|
|
4
4
|
* Throttles the JS `onProgress` fan-out to a configurable cadence, with an
|
|
5
5
|
* optional reduced rate while the app is backgrounded. Pure + deterministic
|
|
6
|
-
* (the caller supplies a monotonic timestamp)
|
|
6
|
+
* (the caller supplies a monotonic timestamp).
|
|
7
7
|
*
|
|
8
8
|
* This gates ONLY the JS emission — the native 2 Hz sampler keeps running, so
|
|
9
9
|
* milestone detection and buffer-state recomputation stay full-rate. A tick
|
|
@@ -2,7 +2,7 @@ package com.margelo.nitro.queueplayer
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Pure-Kotlin index-shift arithmetic for queue mutations. Extracted
|
|
5
|
-
* from [TrackPlayer] so the shift semantics
|
|
5
|
+
* from [TrackPlayer] so the shift semantics stand alone without
|
|
6
6
|
* an ExoPlayer. Mirrors (and lightly supersedes) the inline math
|
|
7
7
|
* inside iOS `TrackPlayer.swift`'s `addToQueueBody` /
|
|
8
8
|
* `removeFromQueueBody` / `moveInQueueBody` — the iOS backlog carries
|
|
@@ -4,7 +4,7 @@ package com.margelo.nitro.queueplayer
|
|
|
4
4
|
* Pure-Kotlin skip-index arithmetic. Mirrors the iOS sibling
|
|
5
5
|
* `ios/QueueSkipArithmetic.swift` 1-for-1.
|
|
6
6
|
*
|
|
7
|
-
* Extracted from [TrackPlayer] so the logic
|
|
7
|
+
* Extracted from [TrackPlayer] so the logic stands alone without
|
|
8
8
|
* instantiating an ExoPlayer. [TrackPlayer.computeNextIndex] /
|
|
9
9
|
* [TrackPlayer.computePreviousIndex] are thin adapters that translate
|
|
10
10
|
* the Nitrogen-generated [RepeatMode] enum into [QueueSkipRepeatMode]
|
|
@@ -29,7 +29,7 @@ package com.margelo.nitro.queueplayer
|
|
|
29
29
|
*
|
|
30
30
|
* Bias is toward emitting: when in doubt, act rather than swallow a real press.
|
|
31
31
|
*
|
|
32
|
-
* Pure and time-injected ([nowUptimeMs] is passed in) so it
|
|
32
|
+
* Pure and time-injected ([nowUptimeMs] is passed in), so it needs no
|
|
33
33
|
* Android runtime. [shouldEmit] is `@Synchronized` so it is safe regardless of
|
|
34
34
|
* which thread an emit site runs on (today they are all main-thread-confined).
|
|
35
35
|
*/
|
|
@@ -2,7 +2,7 @@ package com.margelo.nitro.queueplayer
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Pure state machine for the sleep timer — no player, volume, or handler
|
|
5
|
-
* dependencies, so it
|
|
5
|
+
* dependencies, so it stands alone. The owning [TrackPlayer]
|
|
6
6
|
* drives it from a repeating main-looper runnable and applies the returned
|
|
7
7
|
* decision (volume fade, pause) to the engine.
|
|
8
8
|
*
|
|
@@ -46,10 +46,9 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
46
46
|
// --- Stored state
|
|
47
47
|
//
|
|
48
48
|
// Mirrors iOS TrackPlayer.swift's "Stored state" block. Field
|
|
49
|
-
// visibility is `internal` + `@VisibleForTesting` so
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
// the JVM unit-test runtime).
|
|
49
|
+
// visibility is `internal` + `@VisibleForTesting` so lifecycle
|
|
50
|
+
// transitions can be observed without going through the JNI-backed
|
|
51
|
+
// Nitro Promise machinery (which does not load on a plain JVM).
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* `true` after [configureInternal] has bound + configured the
|
|
@@ -158,8 +157,7 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
158
157
|
private var lastEmittedFormatMediaItem: MediaItem? = null
|
|
159
158
|
|
|
160
159
|
// The fields below are written on main (via `onMain` / `syncMain`
|
|
161
|
-
// from the Promise adapter path
|
|
162
|
-
// which run on main). They are read off-main by the synchronous
|
|
160
|
+
// from the Promise adapter path). They are read off-main by the synchronous
|
|
163
161
|
// snapshot accessors — `getCurrentTrackIndex`, `getQueue` —
|
|
164
162
|
// dispatched on the JS thread by Nitro. `@Volatile` gives the
|
|
165
163
|
// read path a happens-before edge on the most recent main-thread
|
|
@@ -581,7 +579,7 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
581
579
|
private val progressEmissionGate = ProgressEmissionGate()
|
|
582
580
|
// ProcessLifecycleOwner observer driving the gate's background state. Held in
|
|
583
581
|
// a nullable field so a re-configureInternal without an intervening
|
|
584
|
-
// destroyInternal
|
|
582
|
+
// destroyInternal is a no-op instead of leaking a second
|
|
585
583
|
// observer. Registered in configureInternal, removed in destroyInternal.
|
|
586
584
|
private var progressLifecycleObserver: DefaultLifecycleObserver? = null
|
|
587
585
|
private val errorListeners = ListenerRegistry<(PlaybackError) -> Unit>()
|
|
@@ -866,11 +864,10 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
866
864
|
}
|
|
867
865
|
|
|
868
866
|
/**
|
|
869
|
-
* Lifecycle configure body. `internal
|
|
870
|
-
*
|
|
871
|
-
* to the
|
|
872
|
-
*
|
|
873
|
-
* run on Robolectric's main-thread dispatcher.
|
|
867
|
+
* Lifecycle configure body. `internal`, bypassing the Nitro Promise
|
|
868
|
+
* path. Callers MUST hop to the main thread first — ExoPlayer
|
|
869
|
+
* construction binds to the calling Looper. Production path goes
|
|
870
|
+
* through `onMain`.
|
|
874
871
|
*
|
|
875
872
|
* Builds the ExoPlayer with a [MediaSource.Factory] that attaches
|
|
876
873
|
* the config's HTTP headers + User-Agent on every network request.
|
|
@@ -879,9 +876,8 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
879
876
|
* Per the universal auto-destroy contract every `configure()` call
|
|
880
877
|
* tears the player down upstream so this body is purely
|
|
881
878
|
* constructive — `player` is guaranteed null on entry from the
|
|
882
|
-
* production path.
|
|
883
|
-
*
|
|
884
|
-
* between configures.
|
|
879
|
+
* production path. Any caller driving `configureInternal` directly
|
|
880
|
+
* must call `destroyInternal` first between configures.
|
|
885
881
|
*/
|
|
886
882
|
@VisibleForTesting
|
|
887
883
|
@MainThread
|
|
@@ -2442,9 +2438,9 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
2442
2438
|
/**
|
|
2443
2439
|
* Main-thread body for [setPlaybackSpeed]. The engine applies the
|
|
2444
2440
|
* active pitch-correction mode's pitch alongside the speed (voice/music
|
|
2445
|
-
* preserve pitch; none lets it follow rate). Exposed `@VisibleForTesting
|
|
2446
|
-
*
|
|
2447
|
-
*
|
|
2441
|
+
* preserve pitch; none lets it follow rate). Exposed `@VisibleForTesting`;
|
|
2442
|
+
* centralizes the cast + speed-application logic rather than routing
|
|
2443
|
+
* straight through `ExoPlayer.playbackParameters`.
|
|
2448
2444
|
*
|
|
2449
2445
|
* Diverges from iOS: on iOS `player.rate = Float(rate)` implicitly
|
|
2450
2446
|
* starts playback when the player was paused. Android's
|
|
@@ -3032,6 +3028,8 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
3032
3028
|
override fun onCarDisconnect(callback: () -> Unit): () -> Unit =
|
|
3033
3029
|
deferredRegister { it.registerOnCarDisconnect(callback) }
|
|
3034
3030
|
|
|
3031
|
+
override fun isCarConnected(): Boolean = CarConnectionState.isConnected()
|
|
3032
|
+
|
|
3035
3033
|
override fun onServiceReady(
|
|
3036
3034
|
callback: (reason: ServiceReadyReason) -> Unit
|
|
3037
3035
|
): () -> Unit = deferredRegister { it.registerOnServiceReady(callback) }
|
|
@@ -4157,11 +4155,9 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
4157
4155
|
}
|
|
4158
4156
|
|
|
4159
4157
|
/**
|
|
4160
|
-
*
|
|
4158
|
+
* Stash a [TrackChangeReason] that the next
|
|
4161
4159
|
* [handleMediaItemTransition] with `REASON_SEEK` will consume.
|
|
4162
|
-
* Production code reaches this field via `skipTo*Internal`
|
|
4163
|
-
* bodies; the hook just lets Robolectric tests simulate the
|
|
4164
|
-
* stash without driving a real skip + ExoPlayer seek.
|
|
4160
|
+
* Production code reaches this field via `skipTo*Internal` bodies.
|
|
4165
4161
|
*/
|
|
4166
4162
|
@VisibleForTesting
|
|
4167
4163
|
internal fun setPendingTrackChangeReasonForTest(reason: TrackChangeReason?) {
|
|
@@ -4169,9 +4165,8 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
4169
4165
|
}
|
|
4170
4166
|
|
|
4171
4167
|
/**
|
|
4172
|
-
*
|
|
4173
|
-
*
|
|
4174
|
-
* NONE state without going through a real Player.Listener fire.
|
|
4168
|
+
* Reset the [lastReportedState] dedup edge, forcing [emitStateIfChanged]
|
|
4169
|
+
* to emit from an already-NONE state without a real Player.Listener fire.
|
|
4175
4170
|
*/
|
|
4176
4171
|
@VisibleForTesting
|
|
4177
4172
|
internal fun resetLastReportedStateForTest() {
|
|
@@ -4250,8 +4245,7 @@ class TrackPlayer : HybridTrackPlayerSpec(), PlaybackEngineDelegate {
|
|
|
4250
4245
|
|
|
4251
4246
|
/**
|
|
4252
4247
|
* Decide which [ServiceReadyReason] (if any) to dispatch on a
|
|
4253
|
-
* fresh service-bind. Pure function
|
|
4254
|
-
* is unit-testable without spinning up a service controller.
|
|
4248
|
+
* fresh service-bind. Pure function — no service controller needed.
|
|
4255
4249
|
*
|
|
4256
4250
|
* - First-ever bind ([prior] == null): [ServiceReadyReason.FIRST_BIND].
|
|
4257
4251
|
* - Bind against a different binder identity:
|
|
@@ -7,8 +7,8 @@ import androidx.media3.common.Player
|
|
|
7
7
|
* isPlaying, playWhenReady, playbackSuppressionReason, hasTracks,
|
|
8
8
|
* currentTrackIndex)` tuple to the library's [PlayerState] enum.
|
|
9
9
|
*
|
|
10
|
-
* Extracted from [TrackPlayer.getStateInternal] so every branch
|
|
11
|
-
*
|
|
10
|
+
* Extracted from [TrackPlayer.getStateInternal] so every branch
|
|
11
|
+
* stands alone without a live ExoPlayer. Matches the pattern of
|
|
12
12
|
* [QueueSkipArithmetic] + [QueueMutationArithmetic] — TrackPlayer
|
|
13
13
|
* is a thin adapter that reads the live player's state and
|
|
14
14
|
* delegates the translation here.
|
package/android/src/test/java/com/margelo/nitro/queueplayer/AudioPipelineRenderersFactoryTest.kt
CHANGED
|
@@ -14,12 +14,9 @@ import java.lang.reflect.Field
|
|
|
14
14
|
/**
|
|
15
15
|
* Unit coverage for [AudioPipelineRenderersFactory] construction — it wraps a
|
|
16
16
|
* caller-supplied [androidx.media3.common.audio.AudioProcessorChain] and leaves
|
|
17
|
-
* the produced sink at 16-bit (float output off).
|
|
18
|
-
* `buildAudioSink` via `ExoPlayer.Builder.build()` in
|
|
19
|
-
* [GaplessEngineLifecycleTest] / [CrossfadeEngineLifecycleTest]; `buildAudioSink`
|
|
17
|
+
* the produced sink at 16-bit (float output off). `buildAudioSink`
|
|
20
18
|
* itself is `protected` on [DefaultRenderersFactory] and cannot be called
|
|
21
|
-
* outside the Media3 internal call path.
|
|
22
|
-
* [PitchAwareAudioProcessorChainTest].
|
|
19
|
+
* outside the Media3 internal call path.
|
|
23
20
|
*/
|
|
24
21
|
@RunWith(RobolectricTestRunner::class)
|
|
25
22
|
@Config(sdk = [34])
|
|
@@ -9,10 +9,7 @@ import org.junit.Test
|
|
|
9
9
|
/**
|
|
10
10
|
* Pure-Kotlin coverage for [BrowseCallbackRegistry]'s slot-replace
|
|
11
11
|
* + dispose semantics. The Promise-typed callbacks are stored as
|
|
12
|
-
* function references; tests use simple stand-in lambdas
|
|
13
|
-
* dispatch coverage lives at the integration layer
|
|
14
|
-
* (`PlaybackServiceCallbackSearchTest` for the search dispatch
|
|
15
|
-
* path; future Maestro flows for end-to-end Auto cold-wake).
|
|
12
|
+
* function references; tests use simple stand-in lambdas.
|
|
16
13
|
*/
|
|
17
14
|
@UnstableApi
|
|
18
15
|
class BrowseCallbackRegistryTest {
|
|
@@ -15,8 +15,7 @@ import org.robolectric.annotation.Config
|
|
|
15
15
|
/**
|
|
16
16
|
* Lifecycle + fade-math coverage for [CrossfadeEngine].
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
* Maestro / demo-app integration layer; this suite exercises:
|
|
18
|
+
* This suite exercises:
|
|
20
19
|
* empty-state sentinels, role-swap arithmetic, equal-power gain
|
|
21
20
|
* curve, duration-clamp formula, manual-skip cancellation,
|
|
22
21
|
* release idempotence + delegate clearing.
|
package/android/src/test/java/com/margelo/nitro/queueplayer/CrossfadeEngineReplayGainTest.kt
CHANGED
|
@@ -24,9 +24,7 @@ import org.robolectric.annotation.Config
|
|
|
24
24
|
* Media3 metadata dispatch is not emulated by Robolectric without
|
|
25
25
|
* playback, so the listener body composes its work through the
|
|
26
26
|
* engine-internal `handleReplayGainParse(isA, parsed)` helper which
|
|
27
|
-
* these tests drive directly with synthetic [ReplayGainData].
|
|
28
|
-
* pure-math piece is covered in [ReplayGainGainTest]; end-to-end
|
|
29
|
-
* propagation lands in the demo app's `replaygain` Maestro suite.
|
|
27
|
+
* these tests drive directly with synthetic [ReplayGainData].
|
|
30
28
|
* This file covers the no-data baseline + the per-leg
|
|
31
29
|
* `handleReplayGainParse` cache + recompute contract.
|
|
32
30
|
*/
|
|
@@ -173,8 +171,6 @@ class CrossfadeEngineReplayGainTest {
|
|
|
173
171
|
|
|
174
172
|
// The per-leg cache-clear-on-transition path lives inline in each
|
|
175
173
|
// leg's `Player.Listener.onMediaItemTransition` body. Robolectric
|
|
176
|
-
// does not drive that callback without real playback
|
|
177
|
-
//
|
|
178
|
-
// `cross-track-active-updates` +
|
|
179
|
-
// `skip-next-mid-playback-resets-from-stale-cache`).
|
|
174
|
+
// does not drive that callback without real playback, so it is out
|
|
175
|
+
// of scope here.
|
|
180
176
|
}
|
|
@@ -13,8 +13,7 @@ import org.robolectric.annotation.Config
|
|
|
13
13
|
/**
|
|
14
14
|
* State-mirror coverage for [EqualizerEngine] on the API 28+ path.
|
|
15
15
|
* Robolectric stubs the audio-effect subsystem at this SDK level so
|
|
16
|
-
* `attach` exercises the construction path without throwing
|
|
17
|
-
* audible effect is verified at integration via demo Maestro.
|
|
16
|
+
* `attach` exercises the construction path without throwing.
|
|
18
17
|
*/
|
|
19
18
|
@RunWith(RobolectricTestRunner::class)
|
|
20
19
|
@Config(sdk = [34])
|
|
@@ -16,9 +16,7 @@ import org.robolectric.annotation.Config
|
|
|
16
16
|
/**
|
|
17
17
|
* Wiring coverage for the `Equalizer` HybridObject — engine
|
|
18
18
|
* selection, JS-facing surface routing through the synchronous
|
|
19
|
-
* `*Internal` core, listener registry behaviour.
|
|
20
|
-
* effect is verified at the integration layer via demo Maestro
|
|
21
|
-
* once the engine is hooked to ExoPlayer's audio session.
|
|
19
|
+
* `*Internal` core, listener registry behaviour.
|
|
22
20
|
*/
|
|
23
21
|
@RunWith(RobolectricTestRunner::class)
|
|
24
22
|
@Config(sdk = [34])
|
|
@@ -13,9 +13,8 @@ import org.robolectric.annotation.Config
|
|
|
13
13
|
* State-mirror coverage for [EqualizerLegacyEngine] on the API <28 path.
|
|
14
14
|
* Robolectric's audio-effect shadow doesn't model the hardware-side
|
|
15
15
|
* band centre frequencies + gain range; the band-mapping + dB↔mB
|
|
16
|
-
* conversion are the
|
|
17
|
-
*
|
|
18
|
-
* behaviour varies per OEM).
|
|
16
|
+
* conversion are the invariants this covers. Legacy AudioEffect
|
|
17
|
+
* behaviour varies per OEM.
|
|
19
18
|
*/
|
|
20
19
|
@RunWith(RobolectricTestRunner::class)
|
|
21
20
|
@Config(sdk = [27])
|
|
@@ -19,8 +19,7 @@ import kotlin.math.sin
|
|
|
19
19
|
* Unit coverage for [FFTProcessorTee] — buffer ingestion across PCM
|
|
20
20
|
* encodings, intervalMs throttling, includeSamples flag, and
|
|
21
21
|
* multi-channel mixdown. The Tee callback contract is mocked
|
|
22
|
-
* directly
|
|
23
|
-
* Maestro layer (no Robolectric harness for ExoPlayer audio output).
|
|
22
|
+
* directly.
|
|
24
23
|
*/
|
|
25
24
|
@RunWith(RobolectricTestRunner::class)
|
|
26
25
|
@Config(sdk = [34])
|
|
@@ -15,8 +15,6 @@ import org.robolectric.annotation.Config
|
|
|
15
15
|
/**
|
|
16
16
|
* Lifecycle smoke coverage for [GaplessEngine] — empty-state
|
|
17
17
|
* sentinels and the idempotent / delegate-clearing release contract.
|
|
18
|
-
* Behavioural coverage of transport / queue mutation runs through
|
|
19
|
-
* the existing TrackPlayer integration suites + Maestro flows.
|
|
20
18
|
*/
|
|
21
19
|
@RunWith(RobolectricTestRunner::class)
|
|
22
20
|
@Config(sdk = [34])
|
|
@@ -19,10 +19,8 @@ import org.robolectric.annotation.Config
|
|
|
19
19
|
* Real Media3 metadata dispatch is not emulated by Robolectric
|
|
20
20
|
* without playback, so the listener body composes its work through
|
|
21
21
|
* the engine-internal `handleReplayGainParse` helper which these
|
|
22
|
-
* tests drive directly with synthetic [ReplayGainData].
|
|
23
|
-
*
|
|
24
|
-
* end-to-end propagation lands in the demo app's `replaygain`
|
|
25
|
-
* Maestro suite. This file covers the no-data baseline,
|
|
22
|
+
* tests drive directly with synthetic [ReplayGainData].
|
|
23
|
+
* This file covers the no-data baseline,
|
|
26
24
|
* mode-change-without-data behaviour, and the
|
|
27
25
|
* `handleReplayGainParse` cache + recompute contract.
|
|
28
26
|
*/
|
|
@@ -147,8 +145,5 @@ class GaplessEngineReplayGainTest {
|
|
|
147
145
|
|
|
148
146
|
// The cache-clear-on-transition path lives inline in the
|
|
149
147
|
// `Player.Listener.onMediaItemTransition` body. Robolectric does not
|
|
150
|
-
// drive that callback without real playback
|
|
151
|
-
// covered at the integration layer by `RNQP-Demo/src/tests/suites/
|
|
152
|
-
// replaygain.ts` (steps `cross-track-active-updates` +
|
|
153
|
-
// `skip-next-mid-playback-resets-from-stale-cache`).
|
|
148
|
+
// drive that callback without real playback.
|
|
154
149
|
}
|
|
@@ -21,11 +21,9 @@ import org.robolectric.annotation.Config
|
|
|
21
21
|
* surface: the default no-task `getTaskConfig` contract and the
|
|
22
22
|
* process-wide wake-lock helper.
|
|
23
23
|
*
|
|
24
|
-
* The full `onStartCommand` chain
|
|
24
|
+
* The full `onStartCommand` chain routes through Media3's
|
|
25
25
|
* `MediaLibraryService.onStartCommand` and into native code that
|
|
26
|
-
* Robolectric can't satisfy
|
|
27
|
-
* [PlaybackServiceLifecycleTest] (which subclasses into the new
|
|
28
|
-
* `HeadlessJsMediaService` base) plus the Maestro demo cycle.
|
|
26
|
+
* Robolectric can't satisfy, so it is out of scope here.
|
|
29
27
|
*/
|
|
30
28
|
@RunWith(RobolectricTestRunner::class)
|
|
31
29
|
@Config(sdk = [34])
|
|
@@ -26,11 +26,10 @@ import org.robolectric.annotation.Config
|
|
|
26
26
|
* both produce items — the file/remote routing difference is a
|
|
27
27
|
* DataSource.Factory concern, not a MediaItem concern).
|
|
28
28
|
*
|
|
29
|
-
* Factory-building is
|
|
29
|
+
* Factory-building is checked by type only (the internal
|
|
30
30
|
* `DefaultHttpDataSource.Factory` is configured via a builder chain
|
|
31
31
|
* whose effective state is hard to read back without reflection —
|
|
32
|
-
* the factory is wired into ExoPlayer at construction time
|
|
33
|
-
* exercised implicitly through the TrackPlayer lifecycle tests).
|
|
32
|
+
* the factory is wired into ExoPlayer at construction time).
|
|
34
33
|
*
|
|
35
34
|
* @Config sdk=34 — Robolectric 4.11.1's max supported SDK.
|
|
36
35
|
*/
|
|
@@ -5,9 +5,7 @@ import org.junit.Test
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Unit tests for [MilestoneTracker] — the pure 25/50/75/90% crossing
|
|
8
|
-
* logic behind `onPlaybackMilestone`.
|
|
9
|
-
* seek, track-change reset) is covered by the `playback-milestones`
|
|
10
|
-
* demo suite.
|
|
8
|
+
* logic behind `onPlaybackMilestone`.
|
|
11
9
|
*/
|
|
12
10
|
class MilestoneTrackerTest {
|
|
13
11
|
|
package/android/src/test/java/com/margelo/nitro/queueplayer/NowPlayingFormatExtractorTest.kt
CHANGED
|
@@ -7,8 +7,7 @@ import org.junit.Assert.assertEquals
|
|
|
7
7
|
import org.junit.Test
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Pure-mapping coverage for [NowPlayingFormatExtractor].
|
|
11
|
-
* `extract(player:)` path is exercised through demo suites; these
|
|
10
|
+
* Pure-mapping coverage for [NowPlayingFormatExtractor]. These
|
|
12
11
|
* tests pin the codec / container tables so the JS-visible enum can't
|
|
13
12
|
* drift without a test failure.
|
|
14
13
|
*/
|
package/android/src/test/java/com/margelo/nitro/queueplayer/PitchAwareAudioProcessorChainTest.kt
CHANGED
|
@@ -17,7 +17,7 @@ import org.robolectric.annotation.Config
|
|
|
17
17
|
/**
|
|
18
18
|
* Routing coverage for [PitchAwareAudioProcessorChain]: which stretcher is
|
|
19
19
|
* actually stretching for each [PitchCorrectionMode] and speed. The native
|
|
20
|
-
* stretch itself
|
|
20
|
+
* stretch itself runs on-device; these assert only the mode gate, which
|
|
21
21
|
* runs without the native library.
|
|
22
22
|
*
|
|
23
23
|
* Note Signalsmith is intentionally ALWAYS active on the float path (so Media3's
|
|
@@ -10,8 +10,8 @@ import org.robolectric.annotation.Config
|
|
|
10
10
|
* Unit coverage for [PitchCorrection.playbackParameters], the pure mapping
|
|
11
11
|
* from a [PitchCorrectionMode] + speed to Media3 [androidx.media3.common.PlaybackParameters].
|
|
12
12
|
*
|
|
13
|
-
* Engine wiring (which player the params land on) is
|
|
14
|
-
*
|
|
13
|
+
* Engine wiring (which player the params land on) is out of scope for
|
|
14
|
+
* this pure test.
|
|
15
15
|
*/
|
|
16
16
|
@RunWith(RobolectricTestRunner::class)
|
|
17
17
|
@Config(sdk = [34])
|