@simba-dev/react-native-media-player 1.13.8 → 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.
@@ -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.13.8",
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
- /** Launch params shared with `PlayerActivity` via `getLaunchParams`. */
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. That was
94
- * sound while every launch started a fresh `PlayerActivity` — a new React
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
- * It stops being sound the moment playback is loaded into an already-open
98
- * window: the hook stays mounted across launches, so backing out of a film
99
- * and tapping it again produces the same key and no second load happens.
100
- * The user presses play and nothing occurs.
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
- * - Activity launch (openPlayer/getLaunchParams)
211
- * - Audio without an Activity (startAudioPlayback/stopPlayback)
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
- // ── Activity launch (V12 Phase 3 / V13 Phase 52) ───────────────────────
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
- * `PlayerActivity` and therefore no window and no surface. V20
420
- * Phase C. See `NativeMpvPlayer.ts` for the full reject-code
421
- * contract (`E_INVALID_URI`, `E_ENGINE_UNAVAILABLE`, `E_LOAD_FAILED`,
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;
@@ -468,36 +467,6 @@ export interface MpvPlayerModuleBridge {
468
467
  setSurfaceVisible(visible: boolean): Promise<boolean>;
469
468
  /** Whether a video surface is currently mounted and usable. */
470
469
  isSurfaceMounted(): boolean;
471
- /**
472
- * One-shot accessor for the launch params the most recent
473
- * `openPlayer` call handed to `PlayerActivity`. Returns `null`
474
- * when called from MainActivity or after the first read has
475
- * already consumed the value.
476
- */
477
- // V22.0.0 / 1.5.8 (D-035 fix #6): Kotlin declares this as a
478
- // Promise-returning `@ReactMethod` (the legacy interface above
479
- // lied about it being sync, which led to `setParams(<Promise>)`
480
- // and the `loadFile(undefined)` RedBox). TurboModule codegen
481
- // correctly emits `Promise<LaunchParams | null>`. We unwrap with
482
- // `Promise.resolve(...)` in `useLaunchParams` so callers don't
483
- // need to know about this.
484
- getLaunchParams(): Promise<LaunchParams | null>;
485
-
486
- // V22.0.0 / 1.5.7 (D-034): activity-aware launchParams guard.
487
- //
488
- // Synchronous boolean getter exposing the static
489
- // `MpvBridgeModule.currentActivityIsPlayer` flag. PlayerActivity's
490
- // `onCreate` sets this to `true` BEFORE React mounts; `onDestroy`
491
- // resets it to `false`. `useLaunchParams` consults it via this
492
- // method and short-circuits — returns `null` (without consuming
493
- // the single-shot `lastLaunchParams` queue) when we are in
494
- // MainActivity, a Share Sheet host, or no React host yet.
495
- //
496
- // Pre-1.5.7 consumers (where this method is absent) fall through
497
- // to the legacy unconditional one-shot-queue read in
498
- // `useLaunchParams`, which has the cold-start `<PlayerRoot />`
499
- // regression this D-034 release fixes.
500
- isCurrentActivityPlayer(): boolean;
501
470
 
502
471
  // ── Configuration (V12 Phase 21) ───────────────────────────────────────
503
472
  /**
@@ -711,20 +680,12 @@ const NOOP_BRIDGE: MpvPlayerModuleBridge = {
711
680
  getDuration: () => 0,
712
681
  getPlaybackState: () => 'idle',
713
682
 
714
- // Activity launch
715
- openPlayer: (_uri: string, _title: string | null, _type: 'video' | 'audio', _startPositionMs: number) => {
716
- void _uri;
717
- void _title;
718
- void _type;
719
- void _startPositionMs;
720
- return Promise.resolve(false);
721
- },
722
- // Audio playback without an Activity (V20 Phase C).
683
+ // Playback launch
723
684
  //
724
- // Resolves `false` for the same reason `openPlayer` does: the fallback
725
- // bridge is what jest and web previews get, and it has no engine and
726
- // no service. `false` is falsy and assertable; a throw would take down
727
- // a screen that only wanted to know the launch did not happen.
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.
728
689
  startAudioPlayback: (_options: {
729
690
  uri: string;
730
691
  title?: string;
@@ -749,14 +710,6 @@ const NOOP_BRIDGE: MpvPlayerModuleBridge = {
749
710
  fillVideoBounds: () => Promise.resolve(false),
750
711
  setSurfaceVisible: () => Promise.resolve(false),
751
712
  isSurfaceMounted: () => false,
752
- // V22.0.0 / 1.5.8 (D-035 fix #6): now matches the real
753
- // Promise<LaunchParams | null> runtime return type.
754
- getLaunchParams: () => Promise.resolve(null),
755
-
756
- // V22.0.0 / 1.5.7 (D-034): no-op fallback always reports "not a
757
- // player host" so jest tests + Storybook previews don't render
758
- // PlayerRoot even when lastLaunchParams is somehow pre-populated.
759
- isCurrentActivityPlayer: () => false,
760
713
 
761
714
  // Config
762
715
  setConfig: (_configJson: string) => {
@@ -941,10 +894,10 @@ export function getMpvPlayerModule(): MpvPlayerModuleBridge {
941
894
  * to deriving one. It is warned about instead, because a silent
942
895
  * failure here is a wrong title that nobody can explain.
943
896
  *
944
- * Shared by `commands.loadFile` and `useLaunchPlayback`, which are two
945
- * genuinely different entry points (`openPlayer` → activity → launch
946
- * params versus a direct programmatic load) and would otherwise each
947
- * re-implement the set-then-load ordering.
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.
948
901
  */
949
902
  export function applyForceMediaTitle(bridge: MpvPlayerModuleBridge, title?: string): void {
950
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
- // Promise<boolean> — Kotlin @ReactMethod rejects with
169
- // • E_INVALID_TYPE — type is neither "video" nor "audio"
170
- // • E_AUDIO_REQUIRES_SERVICE — type IS "audio". Audio no longer opens
171
- // a window; it must go through `startAudioPlayback` below. Sending
172
- // "audio" here rejects loudly rather than opening an Activity that
173
- // has no surface and no notification.
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 Activity (V20 Phase C) ──────────────────────────
175
+ // ── Audio playback, no surface ──────────────────────────────────────────
184
176
  /**
185
177
  * Start an AUDIO track in the foreground media service, with no
186
- * `PlayerActivity` and therefore no window and no surface.
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. `PlayerActivity` remains for video because PiP is
194
- * per-Activity *window state* and cannot be attached to a React
195
- * Navigation destination; nothing in the platform requires that of
196
- * audio.
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: launchParamsProp,
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 (extracted
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` (lib 1.8.0) and the `headless`
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
- * render body, and `<SimbaPlayerRoot>` mounted `<PlayerRoot>` *instead
9
- * of* its children whenever launch params were present. A consumer with
10
- * its own chrome therefore had its UI discarded exactly when playback
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 `(uri, startPositionMs)`.
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('SimbaPlayerRoot — headless', () => {
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
- it('still loads the payload (that is the point of the flag)', async () => {
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
- <SimbaPlayerRoot headless>
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('renders children when there are no launch params', async () => {
263
- bridge().getLaunchParams.mockResolvedValue(null);
264
- const {getByText} = await render(
265
- <PlayerProvider>
266
- <SimbaPlayerRoot headless>
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
- <SimbaPlayerRoot>
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(queryByText('consumer-chrome')).toBeNull();
268
+ expect(bridge().getLaunchParams).toBeUndefined();
269
+ expect(bridge().isCurrentActivityPlayer).toBeUndefined();
290
270
  });
291
271
  });
@@ -1,9 +1,9 @@
1
1
  import { useEffect } from 'react';
2
2
  import {
3
- applyForceMediaTitle,
4
3
  getMpvPlayerModule,
5
4
  type LaunchParams,
6
5
  } from '../bridge/MpvPlayerModule';
6
+ import { loadAndPlay } from '../bridge/loadAndPlay';
7
7
 
8
8
  /**
9
9
  * Feed a launch payload to mpv, exactly once per payload.
@@ -49,9 +49,8 @@ export function useLaunchPlayback(
49
49
  ): void {
50
50
  const uri = launchParams?.uri ?? null;
51
51
  const title = launchParams?.title ?? undefined;
52
- const startPositionSec = launchParams?.startPositionMs
53
- ? launchParams.startPositionMs / 1000
54
- : 0;
52
+ const startPositionMs = launchParams?.startPositionMs ?? 0;
53
+ const startPositionSec = startPositionMs > 0 ? startPositionMs / 1000 : 0;
55
54
  // A caller-supplied `requestId` ADDS launch identity to the key; it does
56
55
  // not replace the uri|position part. Without it the key was `uri|position`,
57
56
  // which is not unique across launches: that was only ever sound because
@@ -77,13 +76,10 @@ export function useLaunchPlayback(
77
76
  // it away. Combined with `media-title` never being observed, that
78
77
  // is why every player header read "Simba Player".
79
78
  //
80
- // Must precede `loadFile`: mpv reads the option at load time.
81
- applyForceMediaTitle(bridge, title);
82
- bridge.loadFile(uri);
83
- if (startPositionSec > 0) {
84
- bridge.seekAbsolute(startPositionSec);
85
- }
86
- bridge.play();
79
+ // `loadAndPlay` owns the title-then-load ordering now, shared
80
+ // with `usePlayerActivity.openPlayer` so the two entry points
81
+ // cannot drift into loading a file under the wrong title.
82
+ loadAndPlay(bridge, {uri, title, startPositionMs});
87
83
  } catch {
88
84
  // Bridge not present (jest/web) — ignore.
89
85
  }