@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
@@ -194,7 +194,10 @@ describe('usePlayer (no provider)', () => {
194
194
  expect(typeof c.setScreenBrightness).toBe('function');
195
195
  expect(typeof c.requestNotificationPermission).toBe('function');
196
196
  expect(typeof c.openPlayer).toBe('function');
197
- expect(typeof c.getLaunchParams).toBe('function');
197
+ // V21 F5: `getLaunchParams` is gone. It read a one-shot native queue
198
+ // that only the deleted Activity ever filled, so it would have
199
+ // resolved `null` forever.
200
+ expect((c as Record<string, unknown>).getLaunchParams).toBeUndefined();
198
201
  expect(typeof c.getProperty).toBe('function');
199
202
  expect(typeof c.setProperty).toBe('function');
200
203
  expect(typeof c.observeProperty).toBe('function');
@@ -258,7 +261,7 @@ describe('usePlayer (no provider)', () => {
258
261
  expect(NativeModules.MpvPlayerModule.seekBackward).toHaveBeenCalledWith(3);
259
262
  });
260
263
 
261
- it('commands.openPlayer reshapes {uri,title,type,startPositionMs} into positional bridge args', async () => {
264
+ it('commands.openPlayer sends audio to the foreground service, not a window', async () => {
262
265
  const { result } = await renderHook(() => usePlayer());
263
266
  await result.current.commands.openPlayer({
264
267
  uri: 'file:///song.mp3',
@@ -266,27 +269,56 @@ describe('usePlayer (no provider)', () => {
266
269
  type: 'audio',
267
270
  startPositionMs: 12345,
268
271
  });
269
- expect(NativeModules.MpvPlayerModule.openPlayer).toHaveBeenCalledWith(
270
- 'file:///song.mp3',
271
- 'Song',
272
- 'audio',
273
- 12345,
274
- );
272
+ expect(NativeModules.MpvPlayerModule.startAudioPlayback).toHaveBeenCalledWith({
273
+ uri: 'file:///song.mp3',
274
+ title: 'Song',
275
+ startPositionMs: 12345,
276
+ autoPlay: true,
277
+ });
278
+ // Video never touches the service, and nothing starts an Activity.
279
+ expect(NativeModules.MpvPlayerModule.loadFile).not.toHaveBeenCalled();
275
280
  });
276
281
 
277
- it('commands.openPlayer defaults startPositionMs to 0 when omitted', async () => {
282
+ // V21 F5: video used to be handed to a dedicated Activity via
283
+ // `startActivity`. It now loads into the surface the consumer already
284
+ // mounted. These two tests pin the halves of that that matter.
285
+ it('commands.openPlayer loads video into the mounted surface', async () => {
286
+ NativeModules.MpvPlayerModule.isSurfaceMounted.mockReturnValue(true);
278
287
  const { result } = await renderHook(() => usePlayer());
279
- await result.current.commands.openPlayer({
280
- uri: 'file:///song.mp3',
281
- title: 'Song',
288
+ const ok = await result.current.commands.openPlayer({
289
+ uri: 'file:///film.mp4',
290
+ title: 'Film',
282
291
  type: 'video',
292
+ startPositionMs: 5000,
283
293
  });
284
- expect(NativeModules.MpvPlayerModule.openPlayer).toHaveBeenCalledWith(
285
- 'file:///song.mp3',
286
- 'Song',
287
- 'video',
288
- 0,
294
+ expect(ok).toBe(true);
295
+ // Ordering is the contract: force-media-title is read at load time,
296
+ // and seek must follow load or it applies to the previous file.
297
+ expect(NativeModules.MpvPlayerModule.setProperty).toHaveBeenCalledWith(
298
+ 'force-media-title',
299
+ 'Film',
300
+ );
301
+ expect(NativeModules.MpvPlayerModule.loadFile).toHaveBeenCalledWith(
302
+ 'file:///film.mp4',
289
303
  );
304
+ expect(NativeModules.MpvPlayerModule.seekAbsolute).toHaveBeenCalledWith(5);
305
+ expect(NativeModules.MpvPlayerModule.play).toHaveBeenCalled();
306
+ });
307
+
308
+ // "Must not" test: loading into a surface that does not exist starts
309
+ // audio the user cannot see and reports success. Faithful mutant =
310
+ // delete the `isSurfaceMounted()` guard.
311
+ it('commands.openPlayer REFUSES video when no surface is mounted', async () => {
312
+ NativeModules.MpvPlayerModule.isSurfaceMounted.mockReturnValue(false);
313
+ const { result } = await renderHook(() => usePlayer());
314
+ const ok = await result.current.commands.openPlayer({
315
+ uri: 'file:///film.mp4',
316
+ title: 'Film',
317
+ type: 'video',
318
+ });
319
+ expect(ok).toBe(false);
320
+ expect(NativeModules.MpvPlayerModule.loadFile).not.toHaveBeenCalled();
321
+ expect(NativeModules.MpvPlayerModule.play).not.toHaveBeenCalled();
290
322
  });
291
323
 
292
324
  // V22.0.0 / 1.6.0 additions — surface-widening for the V19 vertical-swipe
@@ -10,6 +10,7 @@ import {
10
10
  MpvFileInfo,
11
11
  applyForceMediaTitle,
12
12
  } from '../bridge/MpvPlayerModule';
13
+ import { loadAndPlay } from '../bridge/loadAndPlay';
13
14
 
14
15
  /**
15
16
  * V13 Phase 51: expanded `PlayerState`. The V12 surface (4 fields)
@@ -247,12 +248,15 @@ export interface PlayerCommands {
247
248
  /** Request the `POST_NOTIFICATIONS` permission on Android 13+. */
248
249
  requestNotificationPermission(): void;
249
250
 
250
- // Activity launch (Phase 52 hooks wrap these for consumer ergonomics)
251
+ // Playback launch
251
252
  /**
252
- * Hand off to the dedicated `PlayerActivity`. Resolves with `true`
253
- * on a successful `startActivity`. The new signature is the V13
254
- * module signature (no `duration` / `source` / `mediaType` — those
255
- * were V11 Redux-dispatch concerns that V13 drops).
253
+ * Launch the given media. `audio` starts the foreground media service;
254
+ * `video` loads into the consumer's already-mounted surface and
255
+ * resolves `false` when no surface is mounted, rather than starting
256
+ * playback nobody can see.
257
+ *
258
+ * V21 F5: video no longer hands off to a dedicated `PlayerActivity`.
259
+ * The signature is unchanged — the video lane's destination is.
256
260
  */
257
261
  openPlayer(opts: {
258
262
  uri: string;
@@ -260,22 +264,6 @@ export interface PlayerCommands {
260
264
  type: 'video' | 'audio';
261
265
  startPositionMs?: number;
262
266
  }): Promise<boolean>;
263
- /**
264
- * One-shot accessor for the launch params the most recent
265
- * `openPlayer` handed to `PlayerActivity`.
266
- *
267
- * V22.0.0 / 1.5.8 (D-035 fix #6): now correctly typed as a
268
- * Promise — the Kotlin bridge method is `@ReactMethod` async.
269
- * The previous sync signature was a type lie that caused
270
- * `setParams(<Promise>)` in the consumer and a downstream
271
- * `loadFile(undefined)` RedBox. Callers should `await` this.
272
- */
273
- getLaunchParams(): Promise<{
274
- uri: string;
275
- title: string;
276
- type: 'video' | 'audio';
277
- startPositionMs: number;
278
- } | null>;
279
267
 
280
268
  // Generic property access (used by audioSettingsService, metadataService)
281
269
  /** Get the value of an mpv property as a string. */
@@ -681,16 +669,25 @@ function buildCommands(): PlayerCommands {
681
669
 
682
670
  openPlayer: async (opts) => {
683
671
  dlog('commands.openPlayer(', opts, ')');
684
- return getMpvPlayerModule().openPlayer(
685
- opts.uri,
686
- opts.title,
687
- opts.type,
688
- opts.startPositionMs ?? 0,
689
- );
690
- },
691
- getLaunchParams: () => {
692
- dlog('commands.getLaunchParams()');
693
- return getMpvPlayerModule().getLaunchParams();
672
+ const bridge = getMpvPlayerModule();
673
+ const startPositionMs = opts.startPositionMs ?? 0;
674
+
675
+ if (opts.type === 'audio') {
676
+ return bridge.startAudioPlayback({
677
+ uri: opts.uri,
678
+ title: opts.title,
679
+ startPositionMs,
680
+ autoPlay: true,
681
+ });
682
+ }
683
+
684
+ // Video: refuse when there is no surface rather than loading into
685
+ // nothing. See `usePlayerActivity.openPlayer` for why.
686
+ if (!bridge.isSurfaceMounted()) {
687
+ return false;
688
+ }
689
+ loadAndPlay(bridge, {uri: opts.uri, title: opts.title, startPositionMs});
690
+ return true;
694
691
  },
695
692
 
696
693
  getProperty: (name: string) => {
@@ -1,36 +0,0 @@
1
- package com.simba.player
2
-
3
- /**
4
- * Module-side contract that lets `PlayerActivity` (in the module) read
5
- * the latest `PlayerConfig` (set by `<PlayerProvider config={...}>` in
6
- * JS) without crossing the Gradle module boundary into the consumer
7
- * app's bridge code.
8
- *
9
- * Pattern mirrors [IPipModeChangeEmitter] (Phase 10): the consumer app's
10
- * `MpvBridgeModule` implements this contract; module code looks it up
11
- * via `reactContext.getNativeModule("MpvPlayerModule") as?
12
- * IMpvConfigProvider` and casts. The cast is safe because we control
13
- * both sides of the boundary.
14
- *
15
- * Phase 21 deliverable: `PlayerActivity.onCreate` looks up the bridge
16
- * module and calls [getCurrentConfig] so the activity logs which keys
17
- * are active (matches the spec's "verify config is picked up" step).
18
- * Future phases (22-25) extend the lookup to read theme + pip + audio
19
- * settings and apply them.
20
- *
21
- * Why this survives V20 Phase A while its sibling did not: this contract
22
- * carries data pushed *by React*, so it genuinely needs the React
23
- * context to reach. The native-pointer contract it used to mirror did
24
- * not — it carried a process-global, so V20 replaced it with
25
- * `PlaybackHost`, and it was deleted rather than left as fiction.
26
- */
27
- interface IMpvConfigProvider {
28
- /**
29
- * @return the most recent PlayerConfig pushed via
30
- * `MpvPlayerModule.setConfig(...)`, as a Kotlin Map mirroring
31
- * the JSON structure. `null` when no config has been set
32
- * yet (the consumer app never wrapped its root in
33
- * `<PlayerProvider>`).
34
- */
35
- fun getCurrentConfig(): Map<String, Any?>?
36
- }
@@ -1,31 +0,0 @@
1
- package com.simba.player
2
-
3
- /**
4
- * Module-side contract that lets `PlayerActivity` (in the module)
5
- * emit PiP mode-change events to JS without holding a direct reference
6
- * to `MpvBridgeModule`.
7
- *
8
- * The consumer app's bridge module implements this contract; module code
9
- * looks it up via `reactContext.getNativeModule("MpvPlayerModule") as?
10
- * IPipModeChangeEmitter` and casts. The cast is safe because we control
11
- * both sides.
12
- *
13
- * Phase 10 deliverable: `PlayerActivity.onPictureInPictureModeChanged`
14
- * looks up the bridge module and calls [emitPictureInPictureModeChanged]
15
- * so JS receives the same `onPipModeChanged` event it received in V11
16
- * (where `MainActivity.onPictureInPictureModeChanged` called
17
- * `MpvBridgeModule.onPictureInPictureModeChanged(isInPip)` directly).
18
- *
19
- * Unlike the native-pointer contract this once mirrored, this one
20
- * genuinely needs the React context - it exists to deliver an event
21
- * *to JS*. That is why it survives V20 Phase A while that one was
22
- * deleted and replaced by `PlaybackHost`.
23
- */
24
- interface IPipModeChangeEmitter {
25
- /**
26
- * Tell the JS layer that the activity entered / exited PiP mode.
27
- * Emits an `onPipModeChanged` event with `{ isInPip: Boolean }` to
28
- * the JS `DeviceEventEmitter`.
29
- */
30
- fun emitPictureInPictureModeChanged(isInPictureInPictureMode: Boolean)
31
- }