@simba-dev/react-native-media-player 1.13.7 → 1.14.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/README.md +26 -24
- package/android/src/main/java/com/simba/player/MediaPlaybackService.kt +20 -17
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +18 -307
- package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +32 -5
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -20
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +45 -84
- package/src/bridge/NativeMpvPlayer.ts +15 -52
- package/src/bridge/loadAndPlay.ts +65 -0
- package/src/components/PlayerRoot.tsx +9 -13
- package/src/hooks/__tests__/useLaunchPlayback.test.tsx +44 -64
- package/src/hooks/useLaunchPlayback.ts +7 -11
- package/src/hooks/usePlayerActivity.ts +51 -60
- package/src/index.ts +5 -11
- package/src/types/__tests__/player.test.tsx +49 -17
- package/src/types/player.ts +28 -31
- package/android/src/main/java/com/simba/player/IMpvConfigProvider.kt +0 -36
- package/android/src/main/java/com/simba/player/IPipModeChangeEmitter.kt +0 -31
- package/android/src/main/java/com/simba/player/PlayerActivity.kt +0 -1626
- package/src/hooks/SimbaPlayerRoot.tsx +0 -128
- package/src/hooks/useIsPlayerActivity.ts +0 -61
- package/src/hooks/useLaunchParams.tsx +0 -126
|
@@ -6,6 +6,7 @@ import android.view.Gravity
|
|
|
6
6
|
import android.view.SurfaceHolder
|
|
7
7
|
import android.view.SurfaceView
|
|
8
8
|
import android.view.View
|
|
9
|
+
import android.view.ViewGroup
|
|
9
10
|
import android.widget.FrameLayout
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -99,8 +100,21 @@ class MpvRenderView(context: Context) : SurfaceView(context),
|
|
|
99
100
|
// This is the same mechanism the audio mini bar already relies on.
|
|
100
101
|
|
|
101
102
|
/**
|
|
102
|
-
* Place the surface at an absolute rect, in pixels, inside the
|
|
103
|
-
*
|
|
103
|
+
* Place the surface at an absolute rect, in **window** pixels, inside the
|
|
104
|
+
* host window. Used by the in-app mini player.
|
|
105
|
+
*
|
|
106
|
+
* The coordinates are window-relative on purpose. The only thing that
|
|
107
|
+
* knows a view's window rect is the platform, and RN's
|
|
108
|
+
* `measureInWindow` is the JS-side equivalent of the same space — so
|
|
109
|
+
* accepting window pixels makes "measure a view, hand the result over"
|
|
110
|
+
* a straight pass-through with no coordinate-system translation in the
|
|
111
|
+
* middle. The alternative (content-relative margins) looks simpler but
|
|
112
|
+
* silently disagrees with JS by the window inset, which is zero under
|
|
113
|
+
* edge-to-edge and non-zero the moment that is not — a video that lands
|
|
114
|
+
* offset inside its dock, with nothing in the logs.
|
|
115
|
+
*
|
|
116
|
+
* The conversion to content-relative margins happens here, where the
|
|
117
|
+
* container's own window offset is available and exact.
|
|
104
118
|
*
|
|
105
119
|
* Refuses non-positive extents rather than clamping: a zero-sized
|
|
106
120
|
* SurfaceView is an invalid target for libmpv, and silently substituting
|
|
@@ -112,14 +126,27 @@ class MpvRenderView(context: Context) : SurfaceView(context),
|
|
|
112
126
|
Log.w(TAG, "setVideoBounds refused ${width}x$height at ($x,$y): extents must be > 0")
|
|
113
127
|
return
|
|
114
128
|
}
|
|
129
|
+
val parent = parent as? ViewGroup
|
|
130
|
+
if (parent == null) {
|
|
131
|
+
Log.w(TAG, "setVideoBounds refused: the surface has no container to position within")
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
// Where the container itself starts in window coordinates. Subtracting
|
|
135
|
+
// it turns the caller's window rect into the margin the container
|
|
136
|
+
// expects.
|
|
137
|
+
val containerOffset = IntArray(2)
|
|
138
|
+
parent.getLocationInWindow(containerOffset)
|
|
139
|
+
val left = x - containerOffset[0]
|
|
140
|
+
val top = y - containerOffset[1]
|
|
141
|
+
|
|
115
142
|
val lp = frameParams()
|
|
116
143
|
lp.width = width
|
|
117
144
|
lp.height = height
|
|
118
145
|
lp.gravity = Gravity.TOP or Gravity.START
|
|
119
|
-
lp.leftMargin =
|
|
120
|
-
lp.topMargin =
|
|
146
|
+
lp.leftMargin = left
|
|
147
|
+
lp.topMargin = top
|
|
121
148
|
layoutParams = lp
|
|
122
|
-
Log.i(TAG, "setVideoBounds -> ${width}x$height at ($x,$y)")
|
|
149
|
+
Log.i(TAG, "setVideoBounds -> ${width}x$height at window($x,$y) = margin($left,$top)")
|
|
123
150
|
}
|
|
124
151
|
|
|
125
152
|
/** Expand the surface to fill the host container. */
|
|
@@ -209,24 +209,4 @@ class MpvBridgeModuleTest {
|
|
|
209
209
|
assertEquals("MpvPlayerModule", MpvBridgeModule.NAME)
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
@Test
|
|
213
|
-
fun emitPictureInPictureModeChanged_delegatesToCompanion() {
|
|
214
|
-
// Phase 10 added `IPipModeChangeEmitter` for PlayerActivity
|
|
215
|
-
// (in the module) to call into the companion without crossing
|
|
216
|
-
// the module boundary. Verify it correctly forwards both true
|
|
217
|
-
// and false. We can't easily instantiate MpvBridgeModule without
|
|
218
|
-
// a real ReactApplicationContext; instead, we set the
|
|
219
|
-
// companion's instance to null and confirm the method returns
|
|
220
|
-
// without throwing (it delegates to the same null-guarded
|
|
221
|
-
// companion path).
|
|
222
|
-
assertNull(instanceField.get(null))
|
|
223
|
-
// The instance-method `emitPictureInPictureModeChanged` is
|
|
224
|
-
// defined on the MpvBridgeModule INSTANCE — we can't call it
|
|
225
|
-
// without constructing the module. We instead test the
|
|
226
|
-
// companion path indirectly via the onPictureInPictureModeChanged
|
|
227
|
-
// method which is what the instance method delegates to.
|
|
228
|
-
MpvBridgeModule.onPictureInPictureModeChanged(true)
|
|
229
|
-
MpvBridgeModule.onPictureInPictureModeChanged(false)
|
|
230
|
-
// No exception thrown = delegation works as documented.
|
|
231
|
-
}
|
|
232
212
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "React Native video & audio player powered by libmpv — Picture-in-Picture, MediaSession, foreground service, and a customizable TypeScript UI. Built for Android. Designed as a drop-in replacement for react-native-video / react-native-track-player / expo-av. See CHANGELOG.md for per-version notes.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -80,24 +80,29 @@ export interface MpvAudioDevice {
|
|
|
80
80
|
readonly isDefault: boolean;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* The payload that describes one playback launch, consumed by
|
|
85
|
+
* `loadAndPlay` (directly) and by `useLaunchPlayback` (as its argument).
|
|
86
|
+
*/
|
|
84
87
|
export interface LaunchParams {
|
|
85
88
|
readonly uri: string;
|
|
86
89
|
readonly title: string;
|
|
87
90
|
readonly type: 'video' | 'audio';
|
|
88
91
|
readonly startPositionMs: number;
|
|
89
92
|
/**
|
|
90
|
-
* Monotonic identity of one launch request. Optional
|
|
93
|
+
* Monotonic identity of one launch request. Optional, but in practice
|
|
94
|
+
* every in-window caller needs it.
|
|
91
95
|
*
|
|
92
96
|
* `uri` + `startPositionMs` is not a unique identity for a launch, and
|
|
93
|
-
* `useLaunchPlayback` keys its load effect on exactly that pair.
|
|
94
|
-
*
|
|
95
|
-
* root, so the hook mounted fresh and always fired.
|
|
97
|
+
* `useLaunchPlayback` keys its load effect on exactly that pair. When
|
|
98
|
+
* every launch started a fresh `PlayerActivity`, that was sound — a new
|
|
99
|
+
* React root, so the hook mounted fresh and always fired.
|
|
96
100
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
+
* That world is gone. Playback now loads into an already-open window, so
|
|
102
|
+
* the hook stays mounted across launches and the same key means the
|
|
103
|
+
* second load is skipped: backing out of a film and tapping it again
|
|
104
|
+
* produces the same key, no load happens, and the user presses play and
|
|
105
|
+
* nothing occurs.
|
|
101
106
|
*
|
|
102
107
|
* A caller that loads in-window should therefore supply this. It matches
|
|
103
108
|
* `loadFileWithRequestId`, which already exists for the same reason.
|
|
@@ -207,8 +212,8 @@ export interface CaptureFrameOptions {
|
|
|
207
212
|
* - Property observe + get/set
|
|
208
213
|
* - Filters + playlist
|
|
209
214
|
* - State queries
|
|
210
|
-
* -
|
|
211
|
-
* -
|
|
215
|
+
* - Audio playback (startAudioPlayback/stopPlayback)
|
|
216
|
+
* - Video surface control (setVideoBounds/fillVideoBounds/setSurfaceVisible)
|
|
212
217
|
* - Configuration (setConfig)
|
|
213
218
|
* - PiP + screen
|
|
214
219
|
* - Orientation + immersive
|
|
@@ -401,25 +406,19 @@ export interface MpvPlayerModuleBridge {
|
|
|
401
406
|
/** Get the current playback state. */
|
|
402
407
|
getPlaybackState(): MpvPlaybackState;
|
|
403
408
|
|
|
404
|
-
// ──
|
|
405
|
-
/**
|
|
406
|
-
* Hand off to the dedicated `PlayerActivity`. Returns true on
|
|
407
|
-
* successful `startActivity`. Rejects with `E_INVALID_TYPE`,
|
|
408
|
-
* `E_NO_ACTIVITY`, `E_ACTIVITY_NOT_FOUND`, `E_SECURITY`, or
|
|
409
|
-
* `E_OPEN_PLAYER_FAILED`.
|
|
410
|
-
*/
|
|
411
|
-
openPlayer(
|
|
412
|
-
uri: string,
|
|
413
|
-
title: string | null,
|
|
414
|
-
type: 'video' | 'audio',
|
|
415
|
-
startPositionMs: number,
|
|
416
|
-
): Promise<boolean>;
|
|
409
|
+
// ── Playback launch (V21 F5) ───────────────────────────────────────────
|
|
417
410
|
/**
|
|
418
411
|
* Start an AUDIO track in the foreground media service with no
|
|
419
|
-
*
|
|
420
|
-
* Phase C. See `NativeMpvPlayer.ts` for the full
|
|
421
|
-
* contract (`E_INVALID_URI`, `E_ENGINE_UNAVAILABLE`,
|
|
422
|
-
* `E_START_SERVICE_FAILED`).
|
|
412
|
+
* window and no surface — audio has nothing to draw, so it does not
|
|
413
|
+
* get one. V20 Phase C. See `NativeMpvPlayer.ts` for the full
|
|
414
|
+
* reject-code contract (`E_INVALID_URI`, `E_ENGINE_UNAVAILABLE`,
|
|
415
|
+
* `E_LOAD_FAILED`, `E_START_SERVICE_FAILED`).
|
|
416
|
+
*
|
|
417
|
+
* Video does not come through here at all. It loads into the
|
|
418
|
+
* consumer's already-mounted surface via `loadAndPlay`, because a
|
|
419
|
+
* `SurfaceView`'s Surface belongs to its window: a second window
|
|
420
|
+
* made an in-app video player impossible to build honestly, which is
|
|
421
|
+
* why the dedicated Activity is gone.
|
|
423
422
|
*/
|
|
424
423
|
startAudioPlayback(options: {
|
|
425
424
|
uri: string;
|
|
@@ -436,7 +435,7 @@ export interface MpvPlayerModuleBridge {
|
|
|
436
435
|
isAudioPlaybackServiceRunning(): boolean;
|
|
437
436
|
|
|
438
437
|
/**
|
|
439
|
-
* Resize the video surface to an absolute rect
|
|
438
|
+
* Resize the video surface to an absolute rect, in **window** pixels.
|
|
440
439
|
*
|
|
441
440
|
* V21 places the player in the consumer app's single Activity, where the
|
|
442
441
|
* one surface renders both fullscreen and the in-app mini player's live
|
|
@@ -444,6 +443,14 @@ export interface MpvPlayerModuleBridge {
|
|
|
444
443
|
* remounts the view, so the Surface is not destroyed and mpv does not
|
|
445
444
|
* re-attach.
|
|
446
445
|
*
|
|
446
|
+
* The coordinates are window-relative so a caller can pass straight
|
|
447
|
+
* through what React Native's `measureInWindow` returned, with no
|
|
448
|
+
* coordinate-system translation in the middle. Converting to
|
|
449
|
+
* content-relative margins is the native side's job: it is the only side
|
|
450
|
+
* that knows the window inset, and it is zero under edge-to-edge and
|
|
451
|
+
* non-zero otherwise, so a translation done in JS would be right exactly
|
|
452
|
+
* once and silently wrong after any change to the window setup.
|
|
453
|
+
*
|
|
447
454
|
* Resolves `false` when there is no surface, when the call arrives off the
|
|
448
455
|
* main thread, or when the extents are non-positive. A caller that gets
|
|
449
456
|
* `false` must not present the video as shown.
|
|
@@ -460,36 +467,6 @@ export interface MpvPlayerModuleBridge {
|
|
|
460
467
|
setSurfaceVisible(visible: boolean): Promise<boolean>;
|
|
461
468
|
/** Whether a video surface is currently mounted and usable. */
|
|
462
469
|
isSurfaceMounted(): boolean;
|
|
463
|
-
/**
|
|
464
|
-
* One-shot accessor for the launch params the most recent
|
|
465
|
-
* `openPlayer` call handed to `PlayerActivity`. Returns `null`
|
|
466
|
-
* when called from MainActivity or after the first read has
|
|
467
|
-
* already consumed the value.
|
|
468
|
-
*/
|
|
469
|
-
// V22.0.0 / 1.5.8 (D-035 fix #6): Kotlin declares this as a
|
|
470
|
-
// Promise-returning `@ReactMethod` (the legacy interface above
|
|
471
|
-
// lied about it being sync, which led to `setParams(<Promise>)`
|
|
472
|
-
// and the `loadFile(undefined)` RedBox). TurboModule codegen
|
|
473
|
-
// correctly emits `Promise<LaunchParams | null>`. We unwrap with
|
|
474
|
-
// `Promise.resolve(...)` in `useLaunchParams` so callers don't
|
|
475
|
-
// need to know about this.
|
|
476
|
-
getLaunchParams(): Promise<LaunchParams | null>;
|
|
477
|
-
|
|
478
|
-
// V22.0.0 / 1.5.7 (D-034): activity-aware launchParams guard.
|
|
479
|
-
//
|
|
480
|
-
// Synchronous boolean getter exposing the static
|
|
481
|
-
// `MpvBridgeModule.currentActivityIsPlayer` flag. PlayerActivity's
|
|
482
|
-
// `onCreate` sets this to `true` BEFORE React mounts; `onDestroy`
|
|
483
|
-
// resets it to `false`. `useLaunchParams` consults it via this
|
|
484
|
-
// method and short-circuits — returns `null` (without consuming
|
|
485
|
-
// the single-shot `lastLaunchParams` queue) when we are in
|
|
486
|
-
// MainActivity, a Share Sheet host, or no React host yet.
|
|
487
|
-
//
|
|
488
|
-
// Pre-1.5.7 consumers (where this method is absent) fall through
|
|
489
|
-
// to the legacy unconditional one-shot-queue read in
|
|
490
|
-
// `useLaunchParams`, which has the cold-start `<PlayerRoot />`
|
|
491
|
-
// regression this D-034 release fixes.
|
|
492
|
-
isCurrentActivityPlayer(): boolean;
|
|
493
470
|
|
|
494
471
|
// ── Configuration (V12 Phase 21) ───────────────────────────────────────
|
|
495
472
|
/**
|
|
@@ -703,20 +680,12 @@ const NOOP_BRIDGE: MpvPlayerModuleBridge = {
|
|
|
703
680
|
getDuration: () => 0,
|
|
704
681
|
getPlaybackState: () => 'idle',
|
|
705
682
|
|
|
706
|
-
//
|
|
707
|
-
openPlayer: (_uri: string, _title: string | null, _type: 'video' | 'audio', _startPositionMs: number) => {
|
|
708
|
-
void _uri;
|
|
709
|
-
void _title;
|
|
710
|
-
void _type;
|
|
711
|
-
void _startPositionMs;
|
|
712
|
-
return Promise.resolve(false);
|
|
713
|
-
},
|
|
714
|
-
// Audio playback without an Activity (V20 Phase C).
|
|
683
|
+
// Playback launch
|
|
715
684
|
//
|
|
716
|
-
// Resolves `false`
|
|
717
|
-
//
|
|
718
|
-
//
|
|
719
|
-
//
|
|
685
|
+
// Resolves `false` because the fallback bridge is what jest and web
|
|
686
|
+
// previews get, and it has no engine and no service. `false` is falsy
|
|
687
|
+
// and assertable; a throw would take down a screen that only wanted to
|
|
688
|
+
// know the launch did not happen.
|
|
720
689
|
startAudioPlayback: (_options: {
|
|
721
690
|
uri: string;
|
|
722
691
|
title?: string;
|
|
@@ -741,14 +710,6 @@ const NOOP_BRIDGE: MpvPlayerModuleBridge = {
|
|
|
741
710
|
fillVideoBounds: () => Promise.resolve(false),
|
|
742
711
|
setSurfaceVisible: () => Promise.resolve(false),
|
|
743
712
|
isSurfaceMounted: () => false,
|
|
744
|
-
// V22.0.0 / 1.5.8 (D-035 fix #6): now matches the real
|
|
745
|
-
// Promise<LaunchParams | null> runtime return type.
|
|
746
|
-
getLaunchParams: () => Promise.resolve(null),
|
|
747
|
-
|
|
748
|
-
// V22.0.0 / 1.5.7 (D-034): no-op fallback always reports "not a
|
|
749
|
-
// player host" so jest tests + Storybook previews don't render
|
|
750
|
-
// PlayerRoot even when lastLaunchParams is somehow pre-populated.
|
|
751
|
-
isCurrentActivityPlayer: () => false,
|
|
752
713
|
|
|
753
714
|
// Config
|
|
754
715
|
setConfig: (_configJson: string) => {
|
|
@@ -933,10 +894,10 @@ export function getMpvPlayerModule(): MpvPlayerModuleBridge {
|
|
|
933
894
|
* to deriving one. It is warned about instead, because a silent
|
|
934
895
|
* failure here is a wrong title that nobody can explain.
|
|
935
896
|
*
|
|
936
|
-
* Shared by `
|
|
937
|
-
* genuinely different entry points (
|
|
938
|
-
*
|
|
939
|
-
*
|
|
897
|
+
* Shared by `loadAndPlay` and `commands.loadFile`, which are two
|
|
898
|
+
* genuinely different entry points (a launch payload versus a direct
|
|
899
|
+
* programmatic load) and would otherwise each re-implement the
|
|
900
|
+
* set-then-load ordering.
|
|
940
901
|
*/
|
|
941
902
|
export function applyForceMediaTitle(bridge: MpvPlayerModuleBridge, title?: string): void {
|
|
942
903
|
const trimmed = title?.trim();
|
|
@@ -165,35 +165,30 @@ export interface Spec extends TurboModule {
|
|
|
165
165
|
// ── Video window launch (V12 Phase 3 / V13 Phase 52 / V20 Phase C) ─────
|
|
166
166
|
// VIDEO ONLY as of 1.13.0.
|
|
167
167
|
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
// • E_NO_ACTIVITY / E_ACTIVITY_NOT_FOUND / E_SECURITY /
|
|
175
|
-
// E_OPEN_PLAYER_FAILED
|
|
176
|
-
openPlayer(
|
|
177
|
-
uri: string,
|
|
178
|
-
title: string,
|
|
179
|
-
type: string,
|
|
180
|
-
startPositionMs: number,
|
|
181
|
-
): Promise<boolean>;
|
|
168
|
+
// V21 F5: there is no `openPlayer` here any more. Video used to be
|
|
169
|
+
// handed to a dedicated Activity via `startActivity`; it now loads
|
|
170
|
+
// into the consumer's already-mounted surface, because a
|
|
171
|
+
// `SurfaceView`'s Surface belongs to its window and a second window
|
|
172
|
+
// made an in-app video player impossible to build honestly. Audio goes
|
|
173
|
+
// to `startAudioPlayback` below.
|
|
182
174
|
|
|
183
|
-
// ── Audio playback, no
|
|
175
|
+
// ── Audio playback, no surface ──────────────────────────────────────────
|
|
184
176
|
/**
|
|
185
177
|
* Start an AUDIO track in the foreground media service, with no
|
|
186
|
-
|
|
178
|
+
window and therefore no surface.
|
|
187
179
|
*
|
|
188
180
|
* Why this exists: before V20, `MediaPlaybackService` could only be
|
|
189
181
|
* started from `PlayerActivity.onCreate`, so the session, the media
|
|
190
182
|
* notification and the media-key routing existed *only* while a window
|
|
191
183
|
* was open. Audio was forced into a full-screen Activity purely to get
|
|
192
184
|
* that service running — an Activity exists to draw, and audio has
|
|
193
|
-
* nothing to draw.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
185
|
+
* nothing to draw.
|
|
186
|
+
*
|
|
187
|
+
* Video no longer gets an Activity either, for the same reason in
|
|
188
|
+
* reverse: it loads into the consumer's own mounted surface, so the
|
|
189
|
+
* in-app mini player can show a live picture instead of a poster frame.
|
|
190
|
+
* PiP needed the Activity only as a *host window*, and `MainActivity`
|
|
191
|
+
* hosts it.
|
|
197
192
|
*
|
|
198
193
|
* Both steps happen natively, in this order, and the promise resolves
|
|
199
194
|
* only when both have run:
|
|
@@ -300,38 +295,6 @@ export interface Spec extends TurboModule {
|
|
|
300
295
|
* reads a `WeakReference`.
|
|
301
296
|
*/
|
|
302
297
|
isSurfaceMounted(): boolean;
|
|
303
|
-
// Returns null when no launch is pending or after the first read.
|
|
304
|
-
getLaunchParams(): Promise<{
|
|
305
|
-
uri: string;
|
|
306
|
-
title: string;
|
|
307
|
-
type: string;
|
|
308
|
-
startPositionMs: number;
|
|
309
|
-
} | null>;
|
|
310
|
-
|
|
311
|
-
// V22.0.0 / 1.5.10 (D-034): activity-aware launchParams guard.
|
|
312
|
-
//
|
|
313
|
-
// `MpvBridgeModule.lastLaunchParams` is the canonical handoff from
|
|
314
|
-
// `openPlayer(...)` to the next `PlayerActivity` mount. The previous
|
|
315
|
-
// architecture had `useLaunchParams()` consume it from BOTH
|
|
316
|
-
// MainActivity's React tree and PlayerActivity's React tree.
|
|
317
|
-
// Result on cold start: stale `lastLaunchParams` from a prior
|
|
318
|
-
// `openPlayer` call (set when the user previously tapped a card)
|
|
319
|
-
// was consumed by MainActivity's `<SimbaPlayerRoot>` and rendered
|
|
320
|
-
// `<PlayerRoot />` over the Home screen.
|
|
321
|
-
//
|
|
322
|
-
// The fix: PlayerActivity sets this flag to `true` in onCreate and
|
|
323
|
-
// `false` in onDestroy. `useLaunchParams()` consults it via this
|
|
324
|
-
// synchronous getter and returns `null` (without consuming
|
|
325
|
-
// lastLaunchParams) when we're in MainActivity.
|
|
326
|
-
//
|
|
327
|
-
// Why sync, not Promise: `useLaunchParams` runs the check before the
|
|
328
|
-
// Promise<T> | null decision, so the synchronous bridge path keeps
|
|
329
|
-
// the consumer's render logic straight-line (no Suspense / loading
|
|
330
|
-
// gate at app cold start). Codegen emits a synchronous bridge
|
|
331
|
-
// method as-is when the Kotlin signature is
|
|
332
|
-
// `@ReactMethod(isBlockingSynchronousMethod = true)`.
|
|
333
|
-
isCurrentActivityPlayer(): boolean;
|
|
334
|
-
|
|
335
298
|
// ── Configuration (V12 Phase 21) ───────────────────────────────────────
|
|
336
299
|
setConfig(configJson: string): Promise<number>;
|
|
337
300
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyForceMediaTitle,
|
|
3
|
+
type MpvPlayerModuleBridge,
|
|
4
|
+
} from './MpvPlayerModule';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Feed a launch payload to mpv: title, file, resume position, play.
|
|
8
|
+
*
|
|
9
|
+
* This is the **load lifecycle**, extracted so that every entry point runs
|
|
10
|
+
* the identical sequence. It used to live inline in `useLaunchPlayback`,
|
|
11
|
+
* where it was unreachable from any other caller — which is why
|
|
12
|
+
* `usePlayerActivity.openPlayer` grew its own separate `startActivity`
|
|
13
|
+
* path instead of reusing it. Two implementations of "play this media"
|
|
14
|
+
* is two orderings to keep in sync, and the one that drifts is the one
|
|
15
|
+
* that leaves a file playing under the wrong title.
|
|
16
|
+
*
|
|
17
|
+
* ## The ordering is load-bearing
|
|
18
|
+
*
|
|
19
|
+
* 1. `force-media-title` is read by mpv **at load time**. Set after
|
|
20
|
+
* `loadFile`, it applies to the next file instead of this one, and the
|
|
21
|
+
* header shows a signed CDN token or a filename.
|
|
22
|
+
* 2. `loadFile` must precede `seekAbsolute`, or the seek is applied to
|
|
23
|
+
* the previous file.
|
|
24
|
+
* 3. `play` last. A launch means "play this" — the way to ask for
|
|
25
|
+
* something paused is `pause()` afterwards, never a launch that
|
|
26
|
+
* silently loads and sits there.
|
|
27
|
+
*
|
|
28
|
+
* ## What this deliberately does NOT do
|
|
29
|
+
*
|
|
30
|
+
* It does not size, show, or position the video surface. Presentation has
|
|
31
|
+
* exactly one owner (the consumer's surface controller), and a second
|
|
32
|
+
* owner would be the same "two things resize the surface" defect that
|
|
33
|
+
* produced the black-screen bugs this architecture was rebuilt to remove.
|
|
34
|
+
* This function loads media; something else decides where it appears.
|
|
35
|
+
*
|
|
36
|
+
* It is also **lane-agnostic**: audio playback goes through this exact
|
|
37
|
+
* path and has no surface at all. That is why the surface check lives in
|
|
38
|
+
* `usePlayerActivity.openPlayer` (which knows it was asked for *video*)
|
|
39
|
+
* rather than here.
|
|
40
|
+
*
|
|
41
|
+
* `startPositionMs` is authored in milliseconds because that is what
|
|
42
|
+
* every launch payload carries; `seekAbsolute` speaks seconds, mpv's own
|
|
43
|
+
* unit. The conversion happens here so no caller can get it wrong.
|
|
44
|
+
*
|
|
45
|
+
* Synchronous by design: the underlying bridge methods are fire-and-forget
|
|
46
|
+
* (`loadFile`, `seekAbsolute`, `play` all return `void`). A load failure
|
|
47
|
+
* is not observable at this layer at all — it surfaces through mpv's own
|
|
48
|
+
* `file-loaded` / `end-file` events, which the consumer's state layer
|
|
49
|
+
* already observes. Returning a Promise here would promise a resolution
|
|
50
|
+
* that does not correspond to anything.
|
|
51
|
+
*/
|
|
52
|
+
export function loadAndPlay(
|
|
53
|
+
bridge: MpvPlayerModuleBridge,
|
|
54
|
+
payload: { uri: string; title?: string; startPositionMs?: number },
|
|
55
|
+
): void {
|
|
56
|
+
const {uri, title, startPositionMs = 0} = payload;
|
|
57
|
+
const startPositionSec = startPositionMs > 0 ? startPositionMs / 1000 : 0;
|
|
58
|
+
|
|
59
|
+
applyForceMediaTitle(bridge, title);
|
|
60
|
+
bridge.loadFile(uri);
|
|
61
|
+
if (startPositionSec > 0) {
|
|
62
|
+
bridge.seekAbsolute(startPositionSec);
|
|
63
|
+
}
|
|
64
|
+
bridge.play();
|
|
65
|
+
}
|
|
@@ -3,7 +3,6 @@ import { StyleSheet, View } from 'react-native';
|
|
|
3
3
|
import { DefaultControls, type DefaultControlsProps } from './DefaultControls';
|
|
4
4
|
import { useRenderControls } from './PlayerProvider';
|
|
5
5
|
import { usePlayer } from '../types/player';
|
|
6
|
-
import { useLaunchParams } from '../hooks/useLaunchParams';
|
|
7
6
|
import { useLaunchPlayback } from '../hooks/useLaunchPlayback';
|
|
8
7
|
import {
|
|
9
8
|
getMpvPlayerModule,
|
|
@@ -15,6 +14,13 @@ import { PlayerSurface } from './PlayerSurface';
|
|
|
15
14
|
* Phase 23 + Phase 25 root component for the PlayerActivity JS
|
|
16
15
|
* tree.
|
|
17
16
|
*
|
|
17
|
+
* V21 F5: `launchParams` is now an explicit prop with no implicit
|
|
18
|
+
* fallback. It used to fall back to `useLaunchParams()`, which read a
|
|
19
|
+
* one-shot native queue that only a second Activity ever filled — so the
|
|
20
|
+
* fallback could not fire, and keeping it would have been a branch that
|
|
21
|
+
* looked live and was not. Pass the payload in, or drive loading
|
|
22
|
+
* yourself with the exported `useLaunchPlayback`.
|
|
23
|
+
*
|
|
18
24
|
* Renders the full player UI in two layers:
|
|
19
25
|
* 1. **`<PlayerSurface />`** (Phase 25): the JS-side placeholder
|
|
20
26
|
* for the native SurfaceView that mpv draws into. Fills the
|
|
@@ -75,24 +81,14 @@ export interface PlayerRootProps {
|
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
export function PlayerRoot({
|
|
78
|
-
launchParams
|
|
84
|
+
launchParams,
|
|
79
85
|
}: PlayerRootProps = {}): React.ReactElement {
|
|
80
86
|
const renderControls = useRenderControls();
|
|
81
87
|
const { state, commands } = usePlayer();
|
|
82
|
-
// V22.0.0 / 1.5.8 (D-035 fix #5): prefer the parent's resolved
|
|
83
|
-
// value when it was supplied (the SimbaPlayerRoot path). Fall back
|
|
84
|
-
// to the hook ONLY when the prop was omitted — direct consumers
|
|
85
|
-
// that mount PlayerRoot without SimbaPlayerRoot still need a way
|
|
86
|
-
// to learn the launch params, and the hook is the only entry point
|
|
87
|
-
// in that case.
|
|
88
|
-
const ownLaunchParams = useLaunchParams();
|
|
89
|
-
const launchParams = launchParamsProp ?? ownLaunchParams;
|
|
90
88
|
|
|
91
89
|
// V22.0.0 / 1.5.8 (D-035 fix #3 + #5 + #7): feed the launch URI to
|
|
92
90
|
// mpv exactly once per `(uri, startPositionMs)` payload, NOT once
|
|
93
|
-
// per render. `useLaunchPlayback` owns that contract
|
|
94
|
-
// verbatim from this component in 1.8.0 so `<SimbaPlayerRoot
|
|
95
|
-
// headless>` can keep the same guarantee while delegating the UI).
|
|
91
|
+
// per render. `useLaunchPlayback` owns that contract.
|
|
96
92
|
// The effect is keyed on the URI + start position, so it fires once
|
|
97
93
|
// when the payload resolves to a real URI, then never again until
|
|
98
94
|
// the URI actually changes.
|
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unit tests for `useLaunchPlayback
|
|
3
|
-
* mode of `<SimbaPlayerRoot>`.
|
|
2
|
+
* Unit tests for `useLaunchPlayback`.
|
|
4
3
|
*
|
|
5
4
|
* ## Why these exist
|
|
6
5
|
*
|
|
7
|
-
* Before 1.8.0, the load lifecycle lived inside `<PlayerRoot>`'s
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* started, and the only way to get the load guarantee was to surrender
|
|
12
|
-
* the UI.
|
|
13
|
-
*
|
|
14
|
-
* 1.8.0 splits the two: `useLaunchPlayback` owns the load, and
|
|
15
|
-
* `headless` keeps it while `children` (the consumer's UI) renders
|
|
16
|
-
* unconditionally.
|
|
6
|
+
* Before 1.8.0, the load lifecycle lived inside `<PlayerRoot>`'s render
|
|
7
|
+
* body, so every re-render fired another `loadFile` — and
|
|
8
|
+
* `<PlayerProvider>` re-renders ~1 Hz off the position poll. The hook
|
|
9
|
+
* exists to guarantee a payload is loaded exactly once.
|
|
17
10
|
*
|
|
18
11
|
* ## What these pin
|
|
19
12
|
*
|
|
20
|
-
* - The payload is loaded EXACTLY ONCE per
|
|
21
|
-
* The old render-body version re-fired on every re-render, and
|
|
22
|
-
* `<PlayerProvider>` re-renders ~1 Hz off the position poll.
|
|
13
|
+
* - The payload is loaded EXACTLY ONCE per launch identity.
|
|
23
14
|
* - `startPositionMs` is authored in ms; mpv's `seekAbsolute` is in
|
|
24
15
|
* seconds. A silent unit error here seeks to the wrong place with no
|
|
25
16
|
* error anywhere.
|
|
26
|
-
* - `headless` still loads — that is the whole point of the flag.
|
|
27
17
|
* - A `null` payload is a no-op, not a `loadFile(null)`.
|
|
18
|
+
* - The title is applied BEFORE the load, because mpv reads
|
|
19
|
+
* `force-media-title` at load time.
|
|
20
|
+
*
|
|
21
|
+
* ## V21 F5
|
|
22
|
+
*
|
|
23
|
+
* This hook was one half of the two-Activity launch contract: the other
|
|
24
|
+
* half was a one-shot native queue (`getLaunchParams`) that only the
|
|
25
|
+
* deleted `PlayerActivity` ever filled. Both are gone, so this is now the
|
|
26
|
+
* public in-window launch primitive — a consumer passes the payload and
|
|
27
|
+
* the hook loads it into whatever surface it already has mounted.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import React from 'react';
|
|
31
31
|
import { NativeModules, Text } from 'react-native';
|
|
32
32
|
import { render, waitFor } from '@testing-library/react-native';
|
|
33
33
|
import { useLaunchPlayback } from '../useLaunchPlayback';
|
|
34
|
-
import { SimbaPlayerRoot } from '../SimbaPlayerRoot';
|
|
35
34
|
import { PlayerProvider } from '../../components/PlayerProvider';
|
|
36
35
|
import type { LaunchParams } from '../../bridge/MpvPlayerModule';
|
|
37
36
|
|
|
@@ -221,71 +220,52 @@ describe('useLaunchPlayback', () => {
|
|
|
221
220
|
});
|
|
222
221
|
});
|
|
223
222
|
|
|
224
|
-
describe('
|
|
223
|
+
describe('in-window launch (V21 F5)', () => {
|
|
225
224
|
beforeEach(() => {
|
|
226
225
|
clearBridgeMocks();
|
|
227
|
-
bridge().isCurrentActivityPlayer.mockReturnValue(true);
|
|
228
|
-
bridge().getLaunchParams.mockResolvedValue(PARAMS);
|
|
229
226
|
});
|
|
230
227
|
|
|
231
|
-
|
|
228
|
+
/**
|
|
229
|
+
* The contract that replaced `<SimbaPlayerRoot headless>`.
|
|
230
|
+
*
|
|
231
|
+
* Video no longer starts an Activity, so a consumer drives the load
|
|
232
|
+
* from its own tree and keeps its own UI. This pins the two halves of
|
|
233
|
+
* the regression the `headless` flag used to guard: the module's own
|
|
234
|
+
* player UI must NOT take over the screen, and the payload must load
|
|
235
|
+
* exactly ONCE — two hook instances both firing would load the media
|
|
236
|
+
* twice per launch.
|
|
237
|
+
*/
|
|
238
|
+
function ConsumerChrome() {
|
|
239
|
+
useLaunchPlayback(PARAMS);
|
|
240
|
+
return <Text>consumer-chrome</Text>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
it('loads the payload exactly once and keeps the consumer UI', async () => {
|
|
232
244
|
// RNTL 14: `render` returns a Promise, so its queries must be
|
|
233
245
|
// awaited off the resolved value — destructuring the Promise
|
|
234
246
|
// itself yields `undefined` for every query.
|
|
235
|
-
await render(
|
|
247
|
+
const {queryByText, getByText} = await render(
|
|
236
248
|
<PlayerProvider>
|
|
237
|
-
<
|
|
238
|
-
<Text>consumer-chrome</Text>
|
|
239
|
-
</SimbaPlayerRoot>
|
|
249
|
+
<ConsumerChrome />
|
|
240
250
|
</PlayerProvider>,
|
|
241
251
|
);
|
|
242
252
|
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
243
253
|
expect(bridge().loadFile).toHaveBeenCalledWith(PARAMS.uri);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
it("renders the consumer's children even when launch params exist", async () => {
|
|
247
|
-
// This is the regression 1.8.0 exists to fix: pre-1.8.0, params
|
|
248
|
-
// present meant children were DISCARDED and <PlayerRoot /> took
|
|
249
|
-
// over the screen.
|
|
250
|
-
const {queryByText, getByText} = await render(
|
|
251
|
-
<PlayerProvider>
|
|
252
|
-
<SimbaPlayerRoot headless>
|
|
253
|
-
<Text>consumer-chrome</Text>
|
|
254
|
-
</SimbaPlayerRoot>
|
|
255
|
-
</PlayerProvider>,
|
|
256
|
-
);
|
|
257
|
-
await waitFor(() => expect(getByText('consumer-chrome')).toBeTruthy());
|
|
258
|
-
// The module's own default controls must NOT be on screen.
|
|
254
|
+
expect(getByText('consumer-chrome')).toBeTruthy();
|
|
259
255
|
expect(queryByText('Simba Player')).toBeNull();
|
|
260
256
|
});
|
|
261
257
|
|
|
262
|
-
it('
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
<Text>consumer-chrome</Text>
|
|
268
|
-
</SimbaPlayerRoot>
|
|
269
|
-
</PlayerProvider>,
|
|
270
|
-
);
|
|
271
|
-
await waitFor(() => expect(getByText('consumer-chrome')).toBeTruthy());
|
|
272
|
-
expect(bridge().loadFile).not.toHaveBeenCalled();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('omitting headless keeps the pre-1.8.0 behaviour', async () => {
|
|
276
|
-
// Back-compat guard: the default must still mount the module's own
|
|
277
|
-
// player UI, discard children, AND — critically — still load
|
|
278
|
-
// exactly ONCE. `<SimbaPlayerRoot>` and `<PlayerRoot>` both call
|
|
279
|
-
// `useLaunchPlayback`; if both were active the media would load
|
|
280
|
-
// twice per launch.
|
|
281
|
-
const {queryByText} = await render(
|
|
258
|
+
it('never reads the deleted one-shot launch-params queue', async () => {
|
|
259
|
+
// V21 F5: `getLaunchParams` / `isCurrentActivityPlayer` no longer
|
|
260
|
+
// exist. A consumer that mounted the module's root no longer had a
|
|
261
|
+
// queue to consume, so it must not be consulted for anything.
|
|
262
|
+
await render(
|
|
282
263
|
<PlayerProvider>
|
|
283
|
-
<
|
|
284
|
-
<Text>consumer-chrome</Text>
|
|
285
|
-
</SimbaPlayerRoot>
|
|
264
|
+
<ConsumerChrome />
|
|
286
265
|
</PlayerProvider>,
|
|
287
266
|
);
|
|
288
267
|
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
289
|
-
expect(
|
|
268
|
+
expect(bridge().getLaunchParams).toBeUndefined();
|
|
269
|
+
expect(bridge().isCurrentActivityPlayer).toBeUndefined();
|
|
290
270
|
});
|
|
291
271
|
});
|