@simba-dev/react-native-media-player 1.13.8 → 1.15.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.
Files changed (27) hide show
  1. package/README.md +26 -24
  2. package/android/src/main/java/com/simba/player/MediaPlaybackService.kt +20 -17
  3. package/android/src/main/java/com/simba/player/PlayerPackage.kt +21 -6
  4. package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +18 -307
  5. package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +100 -0
  6. package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +116 -31
  7. package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -20
  8. package/package.json +2 -2
  9. package/src/bridge/MpvPlayerModule.ts +36 -83
  10. package/src/bridge/NativeMpvPlayer.ts +15 -52
  11. package/src/bridge/loadAndPlay.ts +65 -0
  12. package/src/components/PlayerRoot.tsx +9 -13
  13. package/src/components/SimbaVideo.tsx +121 -0
  14. package/src/components/__tests__/SimbaVideo.test.tsx +164 -0
  15. package/src/hooks/__tests__/useLaunchPlayback.test.tsx +44 -64
  16. package/src/hooks/useLaunchPlayback.ts +7 -11
  17. package/src/hooks/usePlayerActivity.ts +51 -60
  18. package/src/index.ts +11 -11
  19. package/src/specs/SimbaVideoViewNativeComponent.ts +84 -0
  20. package/src/types/__tests__/player.test.tsx +49 -17
  21. package/src/types/player.ts +28 -31
  22. package/android/src/main/java/com/simba/player/IMpvConfigProvider.kt +0 -36
  23. package/android/src/main/java/com/simba/player/IPipModeChangeEmitter.kt +0 -31
  24. package/android/src/main/java/com/simba/player/PlayerActivity.kt +0 -1626
  25. package/src/hooks/SimbaPlayerRoot.tsx +0 -128
  26. package/src/hooks/useIsPlayerActivity.ts +0 -61
  27. package/src/hooks/useLaunchParams.tsx +0 -126
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Contract tests for `<SimbaVideo>`.
3
+ *
4
+ * These pin the promise the component makes to a consumer: it is an ordinary
5
+ * React Native view that React Native lays out, and every prop on it either
6
+ * reaches the native view or has a stated default.
7
+ *
8
+ * The native component is mocked as a host element ('SimbaVideoView') and
9
+ * located by testID. RNTL 14 has no `getByType` - only semantic queries - and
10
+ * a testID lookup that succeeds is itself the proof that matters: the view is
11
+ * reachable *through the React tree*. That is the whole regression this
12
+ * component exists to fix. The old picture was mounted by Kotlin at
13
+ * `android.R.id.content`, a sibling of the React root, so no React query could
14
+ * ever have found it.
15
+ */
16
+ import React from 'react';
17
+ import { render, screen } from '@testing-library/react-native';
18
+
19
+ import { SimbaVideo, type SimbaVideoProps } from '../SimbaVideo';
20
+
21
+ jest.mock('../../specs/SimbaVideoViewNativeComponent', () => ({
22
+ __esModule: true,
23
+ default: 'SimbaVideoView',
24
+ }));
25
+
26
+ const TEST_ID = 'native-video';
27
+
28
+ // `jest.setup.ts` already installs `getNativePtr: fn(() => 0)` on
29
+ // NativeModules.MpvPlayerModule.
30
+ const bridge = () =>
31
+ require('react-native').NativeModules.MpvPlayerModule as {
32
+ getNativePtr: jest.Mock;
33
+ };
34
+
35
+ /** Render and return the props that actually cross into the native view. */
36
+ async function renderNative(
37
+ props: Partial<SimbaVideoProps> = {},
38
+ ): Promise<Record<string, unknown>> {
39
+ await render(<SimbaVideo testID={TEST_ID} {...props} />);
40
+ return screen.getByTestId(TEST_ID).props as Record<string, unknown>;
41
+ }
42
+
43
+ describe('SimbaVideo', () => {
44
+ beforeEach(() => {
45
+ jest.clearAllMocks();
46
+ bridge().getNativePtr.mockReturnValue(0);
47
+ });
48
+
49
+ it('renders a real native view reachable through the React tree', async () => {
50
+ // If this test needs changing, the surface is no longer in the tree.
51
+ await render(<SimbaVideo testID={TEST_ID} />);
52
+
53
+ expect(screen.getByTestId(TEST_ID)).toBeTruthy();
54
+ });
55
+
56
+ describe('nativePtr', () => {
57
+ it('resolves the handle from the bridge when the prop is absent', async () => {
58
+ bridge().getNativePtr.mockReturnValue(4242);
59
+
60
+ const p = await renderNative();
61
+
62
+ expect(p.nativePtr).toBe(4242);
63
+ });
64
+
65
+ it('prefers an explicit prop and does not consult the bridge', async () => {
66
+ // An app managing more than one engine passes its own handle. Silently
67
+ // preferring the singleton would bind the wrong engine with no error.
68
+ const p = await renderNative({ nativePtr: 99 });
69
+
70
+ expect(p.nativePtr).toBe(99);
71
+ expect(bridge().getNativePtr).not.toHaveBeenCalled();
72
+ });
73
+
74
+ it('passes the handle through unrounded', async () => {
75
+ // mpv handles are 64-bit. An Int32 round-trip would hand mpv a pointer
76
+ // to nothing, and the symptom would be "video never appears" rather
77
+ // than a type error.
78
+ const big = 9007199254740991; // > Number.MAX_SAFE_INTEGER
79
+ const p = await renderNative({ nativePtr: big });
80
+
81
+ expect(p.nativePtr).toBe(big);
82
+ });
83
+ });
84
+
85
+ describe('resizeMode maps onto mpv video-zoom', () => {
86
+ it('contain is the default and maps to 0 (fit, letterboxed)', async () => {
87
+ expect((await renderNative()).resizeMode).toBe('0');
88
+ });
89
+
90
+ it('contain → 0 when asked for explicitly', async () => {
91
+ expect((await renderNative({ resizeMode: 'contain' })).resizeMode).toBe('0');
92
+ });
93
+
94
+ it('cover → 1 (fill, cropping, aspect preserved)', async () => {
95
+ expect((await renderNative({ resizeMode: 'cover' })).resizeMode).toBe('1');
96
+ });
97
+
98
+ it('stretch → 2 (fill, aspect ignored)', async () => {
99
+ expect((await renderNative({ resizeMode: 'stretch' })).resizeMode).toBe('2');
100
+ });
101
+
102
+ it('falls back to fit for an unrecognised mode', async () => {
103
+ // mpv would reject an unknown video-zoom value; a wrong-but-valid
104
+ // letterbox is recoverable, a rejected property is not.
105
+ const p = await renderNative({ resizeMode: 'bogus' as never });
106
+ expect(p.resizeMode).toBe('0');
107
+ });
108
+ });
109
+
110
+ describe('defaults', () => {
111
+ it('applies stated defaults for every prop that reaches native', async () => {
112
+ // A native view defaulting to "unset" while Kotlin defaults to
113
+ // something else is how a prop ends up looking accepted while doing
114
+ // nothing.
115
+ const p = await renderNative();
116
+
117
+ expect(p.paused).toBe(false);
118
+ expect(p.muted).toBe(false);
119
+ expect(p.volume).toBe(100);
120
+ });
121
+
122
+ it('honours explicit values over defaults', async () => {
123
+ const p = await renderNative({ paused: true, muted: true, volume: 35 });
124
+
125
+ expect(p.paused).toBe(true);
126
+ expect(p.muted).toBe(true);
127
+ expect(p.volume).toBe(35);
128
+ });
129
+ });
130
+
131
+ describe('layout', () => {
132
+ it('carries a full-bleed default style', async () => {
133
+ // A caller who forgets a style must not get a zero-height surface.
134
+ // That renders no frames and reports no error anywhere - the exact
135
+ // failure this project keeps having to chase.
136
+ const style = (await renderNative()).style as Array<
137
+ Record<string, unknown>
138
+ >;
139
+
140
+ expect(style[0]).toMatchObject({
141
+ position: 'absolute',
142
+ top: 0,
143
+ left: 0,
144
+ right: 0,
145
+ bottom: 0,
146
+ });
147
+ });
148
+
149
+ it('lets the caller override the default style', async () => {
150
+ const style = (await renderNative({ style: { flex: 1 } }))
151
+ .style as Array<Record<string, unknown>>;
152
+
153
+ expect(style[1]).toEqual({ flex: 1 });
154
+ });
155
+ });
156
+
157
+ it('forwards unknown props through to the native view', async () => {
158
+ await render(
159
+ <SimbaVideo testID={TEST_ID} accessibilityLabel="Video" />,
160
+ );
161
+
162
+ expect(screen.getByTestId(TEST_ID).props.accessibilityLabel).toBe('Video');
163
+ });
164
+ });
@@ -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
  }
@@ -1,8 +1,6 @@
1
1
  import { useMemo } from 'react';
2
- import {
3
- getMpvPlayerModule,
4
- type LaunchParams,
5
- } from '../bridge/MpvPlayerModule';
2
+ import { getMpvPlayerModule } from '../bridge/MpvPlayerModule';
3
+ import { loadAndPlay } from '../bridge/loadAndPlay';
6
4
 
7
5
  /**
8
6
  * Options accepted by `usePlayerActivity().openPlayer(opts)`. This is
@@ -17,16 +15,16 @@ export interface OpenPlayerOptions {
17
15
  /** Display title for the notification / top bar. */
18
16
  title: string;
19
17
  /**
20
- * `'video'` opens `PlayerActivity`. `'audio'` does NOT — it starts the
21
- * foreground media service and plays with no window at all.
18
+ * `'video'` loads into the mounted surface; `'audio'` starts the
19
+ * foreground media service and plays with no surface at all.
22
20
  *
23
21
  * That fork lives here rather than at the call sites on purpose.
24
22
  * Three separate entry points reach this hook (`openPlayer`,
25
23
  * `useOpenWithResume`, `useOpenPlaylist`) and a consumer has no way to
26
24
  * tell which one a given screen uses. Deciding "does audio need a
27
- * window?" at each of those would mean three places to keep in sync,
28
- * and the one forgotten would open a blank full-screen player for a
29
- * track with no surface.
25
+ * surface?" at each of those would mean three places to keep in sync,
26
+ * and the one forgotten would start a foreground service for a track
27
+ * with no notification artwork.
30
28
  */
31
29
  type: 'video' | 'audio';
32
30
  /** Resume position in milliseconds. 0 (or omitted) starts from the beginning. */
@@ -35,9 +33,10 @@ export interface OpenPlayerOptions {
35
33
  * Optional artwork for the media notification's large icon — a local
36
34
  * path, `file://`, or an `http(s)` URL.
37
35
  *
38
- * Audio only: `PlayerActivity` shows the video frame itself, so it has
39
- * nothing to be handed. Consumed by `startAudioPlayback`; ignored on
40
- * the video path, which is why passing it unconditionally is safe.
36
+ * Audio only: video renders into the consumer's own surface and the
37
+ * module never builds a notification for it, so it has nothing to be
38
+ * handed. Consumed by `startAudioPlayback`; ignored on the video path,
39
+ * which is why passing it unconditionally is safe.
41
40
  */
42
41
  artworkPath?: string;
43
42
  /**
@@ -50,27 +49,32 @@ export interface OpenPlayerOptions {
50
49
  }
51
50
 
52
51
  /**
53
- * V13 Phase 52: thin wrapper around `bridge.openPlayer` +
54
- * `bridge.getLaunchParams`. Replaces the consumer's V11
55
- * `usePlaybackCommands()` hook for the 33+ call sites that
56
- * previously launched `PlayerActivity` from screens like
57
- * `NowPlaying`, `AllVideos`, `Bookmarks`, etc.
52
+ * Thin wrapper around the two launch paths, kept as a hook rather than a
53
+ * bare function so a consumer can `jest.mock` the whole module when it
54
+ * needs to stub launching from a test.
58
55
  *
59
56
  * Why a separate hook (not just `usePlayer().commands.openPlayer`):
60
- * - `usePlayer()` requires a `<PlayerProvider>` ancestor for
61
- * live state; the activity-launch calls happen from screen
62
- * components (lists, grids) that are NOT inside the player
63
- * activity yet.
57
+ * - `usePlayer()` requires a `<PlayerProvider>` ancestor for live state;
58
+ * launch calls happen from screen components (lists, grids) that are
59
+ * not inside a player subtree.
64
60
  * - Returning a smaller surface keeps the screen-side code
65
61
  * self-documenting: "this screen launches the player" vs
66
62
  * "this screen is inside the player".
67
- * - Easier to mock in consumer-side tests (jest.mock the
68
- * whole `usePlayerActivity` module).
69
63
  *
70
- * The hook is non-throwing: the bridge resolves to a no-op
71
- * fallback in jest / web previews, so `openPlayer` resolves with
72
- * `false` and `getLaunchParams` returns `null` — both clearly
73
- * falsy, easy to assert against.
64
+ * ## Video loads in-window (V21 F5)
65
+ *
66
+ * Video used to be handed to a dedicated `PlayerActivity` via
67
+ * `startActivity`. That is gone: the module now loads into the surface
68
+ * the consumer already has mounted, which is the whole reason the
69
+ * two-Activity architecture was removed — a `SurfaceView`'s Surface
70
+ * belongs to its window, so a second window made an in-app video
71
+ * mini-player impossible to build honestly.
72
+ *
73
+ * **The video branch refuses when no surface is mounted** and resolves
74
+ * `false`. Loading into nothing would start audio with no picture and
75
+ * report success, which is the "looks live and is not" failure this
76
+ * module exists to avoid. Presentation stays with the consumer's
77
+ * surface controller; this only decides *whether the load can happen*.
74
78
  *
75
79
  * @example
76
80
  * ```tsx
@@ -90,30 +94,14 @@ export interface OpenPlayerOptions {
90
94
  */
91
95
  export interface UsePlayerActivityResult {
92
96
  /**
93
- * Launch the dedicated `PlayerActivity` with the given media.
94
- * Resolves with `true` on a successful `startActivity` and
95
- * `false` otherwise (e.g. when the activity is unavailable on
96
- * the device, the URI is unplayable, or the bridge is in
97
- * no-op mode).
97
+ * Launch the given media. For `audio` this starts the foreground
98
+ * media service; for `video` it loads into the mounted surface.
99
+ * Resolves `true` when the launch was dispatched and `false`
100
+ * otherwise — audio could not start the service, or video was asked
101
+ * for while no surface was mounted, or the bridge is in no-op mode
102
+ * (jest / web preview, where there is no engine and no surface).
98
103
  */
99
104
  openPlayer(opts: OpenPlayerOptions): Promise<boolean>;
100
- /**
101
- * One-shot accessor for the launch params the most recent
102
- * `openPlayer` call handed to `PlayerActivity`. Resolves
103
- * with `null` when called from MainActivity or after the
104
- * first read has already consumed the value. The Kotlin
105
- * side keeps a single-shot queue, so call this exactly
106
- * once per `PlayerActivity.onCreate`.
107
- *
108
- * V22.0.0 / 1.5.8 (D-035 fix #6): the runtime returns a
109
- * Promise (Kotlin `@ReactMethod` async). The previous sync
110
- * return type was a type lie — the hook stored the
111
- * Promise in `useState`, `if (launchParams != null)` was
112
- * true (Promise is truthy), and downstream `bridge.loadFile`
113
- * got `undefined` → `IllegalArgumentException` at the
114
- * Kotlin bridge. Callers must `await` this.
115
- */
116
- getLaunchParams(): Promise<LaunchParams | null>;
117
105
  }
118
106
 
119
107
  export function usePlayerActivity(): UsePlayerActivityResult {
@@ -123,7 +111,7 @@ export function usePlayerActivity(): UsePlayerActivityResult {
123
111
  const bridge = getMpvPlayerModule();
124
112
  const startPositionMs = opts.startPositionMs ?? 0;
125
113
 
126
- // Audio never opens a window. See `OpenPlayerOptions.type`.
114
+ // Audio never touches a surface. See `OpenPlayerOptions.type`.
127
115
  if (opts.type === 'audio') {
128
116
  return bridge.startAudioPlayback({
129
117
  uri: opts.uri,
@@ -141,18 +129,21 @@ export function usePlayerActivity(): UsePlayerActivityResult {
141
129
  });
142
130
  }
143
131
 
144
- return bridge.openPlayer(
145
- opts.uri,
146
- opts.title,
147
- opts.type,
132
+ // Video: refuse rather than load into nothing. See the class
133
+ // docblock — reporting success here would start playback the
134
+ // user cannot see and the caller cannot detect.
135
+ if (!bridge.isSurfaceMounted()) {
136
+ return Promise.resolve(false);
137
+ }
138
+
139
+ loadAndPlay(bridge, {
140
+ uri: opts.uri,
141
+ title: opts.title,
148
142
  startPositionMs,
149
- );
150
- },
151
- getLaunchParams: () => {
152
- const bridge = getMpvPlayerModule();
153
- return bridge.getLaunchParams();
143
+ });
144
+ return Promise.resolve(true);
154
145
  },
155
146
  }),
156
147
  [],
157
148
  );
158
- }
149
+ }
package/src/index.ts CHANGED
@@ -26,6 +26,12 @@ export {
26
26
 
27
27
  export { PlayerRoot } from './components/PlayerRoot';
28
28
 
29
+ export {
30
+ SimbaVideo,
31
+ type SimbaVideoProps,
32
+ type SimbaVideoResizeMode,
33
+ } from './components/SimbaVideo';
34
+
29
35
  export { PlayerSurface, type PlayerSurfaceProps } from './components/PlayerSurface';
30
36
 
31
37
  export {
@@ -76,7 +82,6 @@ export {
76
82
  } from './hooks/useOpenWithResume';
77
83
 
78
84
  export {SimbaPlayer, type SimbaPlayerProps, type ResumePolicy} from './hooks/SimbaPlayer';
79
- export {SimbaPlayerRoot, type SimbaPlayerRootProps} from './hooks/SimbaPlayerRoot';
80
85
  export {useOpenFromUrl} from './hooks/useOpenFromUrl';
81
86
  export {
82
87
  useOpenPlaylist,
@@ -99,7 +104,6 @@ export {
99
104
  useQueueSelectedIndices,
100
105
  type PlayerQueueSelectionStore,
101
106
  } from './hooks/useQueueSelection';
102
- export {useLaunchParams} from './hooks/useLaunchParams';
103
107
  // v1.10.0 — the "frame at the position you left off" thumbnail. The
104
108
  // first genuinely PUBLIC frame API: `screenshot` / `captureThumbnail`
105
109
  // live in the bridge but were never exported here, so a consumer had
@@ -112,16 +116,12 @@ export {
112
116
  DEFAULT_FRAME_QUALITY,
113
117
  type CaptureFrameOptions,
114
118
  } from './hooks/useResumeThumbnail';
115
- // 1.8.0 — the load half of `<PlayerRoot>`, exposed so a consumer using
116
- // `<SimbaPlayerRoot headless>` (which delegates the player UI) can call
117
- // it directly for a payload the module did not originate. See
118
- // `useLaunchPlayback`'s docstring for the once-per-payload contract.
119
+ // V21 F5 — the load half of `<PlayerRoot>`, and the in-window launch
120
+ // primitive. Video no longer starts an Activity, so a consumer that
121
+ // wants to play media into its own already-mounted surface drives it
122
+ // from here: pass the payload, and `useLaunchPlayback` loads it exactly
123
+ // once. See its docstring for the once-per-payload contract.
119
124
  export {useLaunchPlayback} from './hooks/useLaunchPlayback';
120
- // V19 W6.0 — synchronous, idempotent "is this tree hosted by
121
- // PlayerActivity?" predicate for consumers that render their own
122
- // chrome over the native video surface. See the hook's docstring for
123
- // why `useLaunchParams` is the wrong tool for that question.
124
- export {useIsPlayerActivity} from './hooks/useIsPlayerActivity';
125
125
 
126
126
  export {
127
127
  getMpvPlayerModule,
@@ -0,0 +1,84 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import type {
3
+ Double,
4
+ Float,
5
+ WithDefault,
6
+ } from 'react-native/Libraries/Types/CodegenTypes';
7
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
8
+
9
+ /**
10
+ * Codegen spec for the native mpv video surface.
11
+ *
12
+ * This is the component that makes the picture an ordinary child of the React
13
+ * tree instead of a sibling of the React root. Everything else about SIMBA's
14
+ * video lane follows from that:
15
+ *
16
+ * - React Native owns layout, so the surface gets a real Yoga measure/layout
17
+ * pass. The old path mutated `LayoutParams` straight from Kotlin, which
18
+ * `react-native-video` documents as a hazard - see its `ExoPlayerView`
19
+ * `requestLayout()` override: "React Native (Yoga) can sometimes defer
20
+ * layout passes that are required by ... surface view".
21
+ * - React Native owns z-order, so the video no longer sits behind an opaque
22
+ * React root and no screen has to blank itself around it.
23
+ * - React Native owns the lifecycle, so mount/unmount is the same event for
24
+ * the surface as for any other view.
25
+ *
26
+ * No events are declared in this first revision, deliberately. `MPVLib`
27
+ * forwards decoded mpv events through `onMpvEvent(event, jsonPayload)`, but
28
+ * which event names the C++ layer actually emits has not been verified against
29
+ * a running instance. Shipping an `onReadyForDisplay` prop that never fires
30
+ * would be worse than not shipping it: it would look like a working
31
+ * first-frame signal while being decorative. Events get added once they can be
32
+ * observed.
33
+ */
34
+ export interface NativeProps extends ViewProps {
35
+ /**
36
+ * The mpv handle to bind this surface to, from `getNativePtr()`.
37
+ *
38
+ * `Double`, not `Int32`: mpv handles are 64-bit pointers and an `Int32`
39
+ * prop would truncate them to 32 bits. Codegen maps `Double` to a Kotlin
40
+ * `double`, which carries the full range.
41
+ *
42
+ * May be omitted before the player is initialised. `MpvRenderView` treats a
43
+ * zero handle as "not bindable yet" and re-attaches from `onAttachedToWindow`
44
+ * once a real handle arrives, so an app that renders the view on first paint
45
+ * does not have to wait for the bridge.
46
+ */
47
+ nativePtr?: Double;
48
+
49
+ /**
50
+ * Pause playback. Declarative: set it and the surface pauses, exactly like
51
+ * `react-native-video`'s `paused` prop.
52
+ *
53
+ * Audio-only playback is the case where no view is rendered at all - the
54
+ * engine keeps running with no render target, which is the correct
55
+ * configuration for mpv.
56
+ */
57
+ paused?: WithDefault<boolean, false>;
58
+
59
+ /** Mute. Mirrors `PlayerCommands.setMuted`. */
60
+ muted?: WithDefault<boolean, false>;
61
+
62
+ /**
63
+ * Playback volume, 0..100 - mpv's native range, matching the range
64
+ * `PlayerCommands.setVolume` already exposes. No 0..1 rescaling: one unit
65
+ * system end to end, so a value read from the engine is a value you can hand
66
+ * straight back to it.
67
+ */
68
+ volume?: WithDefault<Float, 100>;
69
+
70
+ /**
71
+ * How the picture fills this view.
72
+ *
73
+ * - `contain` - fit inside, letterboxed. Default, and what every shipping
74
+ * media app uses for fullscreen video.
75
+ * - `cover` - fill the view, cropping the overflow, aspect preserved.
76
+ * - `stretch` - fill the view, aspect ignored.
77
+ *
78
+ * Maps onto mpv's `video-zoom` (0 / 1 / 2) rather than being reimplemented,
79
+ * so it inherits mpv's own scaling and rounding behaviour.
80
+ */
81
+ resizeMode?: WithDefault<string, 'contain'>;
82
+ }
83
+
84
+ export default codegenNativeComponent<NativeProps>('SimbaVideoView');