@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.
- 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/PlayerPackage.kt +21 -6
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +18 -307
- package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +100 -0
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +116 -31
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -20
- package/package.json +2 -2
- package/src/bridge/MpvPlayerModule.ts +36 -83
- package/src/bridge/NativeMpvPlayer.ts +15 -52
- package/src/bridge/loadAndPlay.ts +65 -0
- package/src/components/PlayerRoot.tsx +9 -13
- package/src/components/SimbaVideo.tsx +121 -0
- package/src/components/__tests__/SimbaVideo.test.tsx +164 -0
- 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 +11 -11
- package/src/specs/SimbaVideoViewNativeComponent.ts +84 -0
- 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
|
@@ -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
|
-
|
|
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
|
|
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.
|
|
270
|
-
'file:///song.mp3',
|
|
271
|
-
'Song',
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
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:///
|
|
281
|
-
title: '
|
|
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(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
package/src/types/player.ts
CHANGED
|
@@ -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
|
-
//
|
|
251
|
+
// Playback launch
|
|
251
252
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
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
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
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
|
-
}
|