@simba-dev/react-native-media-player 1.19.0 → 1.20.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.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",
|
|
@@ -504,7 +504,7 @@ export interface MpvPlayerModuleBridge {
|
|
|
504
504
|
|
|
505
505
|
// ── Picture-in-Picture ─────────────────────────────────────────────────
|
|
506
506
|
/** Enter PiP mode; optional chapter title + progress percent for notification. */
|
|
507
|
-
enterPip(chapterTitle?: string, progressPct?: string): void;
|
|
507
|
+
enterPip(chapterTitle?: string | null, progressPct?: string | null): void;
|
|
508
508
|
/** Exit PiP by bringing the activity to the front. */
|
|
509
509
|
exitPip(): void;
|
|
510
510
|
/** Exit PiP and finish the activity. */
|
|
@@ -313,7 +313,14 @@ export interface Spec extends TurboModule {
|
|
|
313
313
|
// Two declarations of one method, disagreeing, is the same class of
|
|
314
314
|
// defect as the MediaKind/MediaLane confusion: the real bug is that
|
|
315
315
|
// there are two sources of truth, not that either value was wrong.
|
|
316
|
-
|
|
316
|
+
//
|
|
317
|
+
// They are declared REQUIRED and nullable here, because that is what
|
|
318
|
+
// the TurboModule boundary actually is: the method has arity 2 and
|
|
319
|
+
// TurboModule checks the argument count on every call. Writing `?`
|
|
320
|
+
// here said "you may call this with no arguments", which is exactly
|
|
321
|
+
// the licence the zero-argument call site took — and the crash it
|
|
322
|
+
// produced was an "expected argument count: 2" rejection.
|
|
323
|
+
enterPip(chapterTitle: string | null, progressPct: string | null): void;
|
|
317
324
|
exitPip(): void;
|
|
318
325
|
exitPipAndFinish(): void;
|
|
319
326
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PiP command must call the native bridge with TWO arguments.
|
|
3
|
+
*
|
|
4
|
+
* The native TurboModule method has arity 2, and TurboModule checks the
|
|
5
|
+
* argument count on EVERY call, so a zero-argument call is rejected
|
|
6
|
+
* before it ever reaches the native body:
|
|
7
|
+
*
|
|
8
|
+
* Exception in HostFunction: TurboModule method "enterPip"
|
|
9
|
+
* called with 0 arguments (expected argument count: 2)
|
|
10
|
+
*
|
|
11
|
+
* That is what the PiP button did: it threw instead of entering PiP.
|
|
12
|
+
* The native side had already been made nullable (v1.9.3) and the
|
|
13
|
+
* codegen spec had already been given two parameters — but the CALL
|
|
14
|
+
* SITE still passed none, and nothing tested the call site's arity.
|
|
15
|
+
*
|
|
16
|
+
* So this file asserts the arity, not the behaviour: a test that only
|
|
17
|
+
* checked "enterPip was called" would pass with a zero-argument call
|
|
18
|
+
* and the bug would survive.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {NativeModules} from 'react-native';
|
|
22
|
+
import {renderHook} from '@testing-library/react-native';
|
|
23
|
+
import {usePlayer} from '../player';
|
|
24
|
+
|
|
25
|
+
function enterPipMock(): jest.Mock {
|
|
26
|
+
return (NativeModules.MpvPlayerModule as unknown as Record<string, jest.Mock>)
|
|
27
|
+
.enterPip;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('commands.enterPip — the native call arity', () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
for (const key of Object.keys(NativeModules.MpvPlayerModule)) {
|
|
33
|
+
const fn = (NativeModules.MpvPlayerModule as unknown as Record<
|
|
34
|
+
string,
|
|
35
|
+
jest.Mock
|
|
36
|
+
>)[key];
|
|
37
|
+
if (typeof fn?.mockClear === 'function') {
|
|
38
|
+
fn.mockClear();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('calls the bridge with TWO arguments even when no values are given', async () => {
|
|
44
|
+
const {result} = await renderHook(() => usePlayer());
|
|
45
|
+
result.current.commands.enterPip();
|
|
46
|
+
|
|
47
|
+
const enterPip = enterPipMock();
|
|
48
|
+
expect(enterPip).toHaveBeenCalledTimes(1);
|
|
49
|
+
// The arity is the whole point: TurboModule rejects anything else.
|
|
50
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
51
|
+
// And the "not supplied" value is null, which the native accepts
|
|
52
|
+
// (its own fallbacks are "Simba Player" and "0 %").
|
|
53
|
+
expect(enterPip.mock.calls[0][0]).toBeNull();
|
|
54
|
+
expect(enterPip.mock.calls[0][1]).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('forwards the chapter title and the progress percentage', async () => {
|
|
58
|
+
const {result} = await renderHook(() => usePlayer());
|
|
59
|
+
result.current.commands.enterPip('Chapter 3', '45 %');
|
|
60
|
+
|
|
61
|
+
const enterPip = enterPipMock();
|
|
62
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
63
|
+
expect(enterPip).toHaveBeenCalledWith('Chapter 3', '45 %');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('passes null for a value that was not supplied, not undefined', async () => {
|
|
67
|
+
const {result} = await renderHook(() => usePlayer());
|
|
68
|
+
result.current.commands.enterPip('Chapter 3', null);
|
|
69
|
+
|
|
70
|
+
const enterPip = enterPipMock();
|
|
71
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
72
|
+
expect(enterPip).toHaveBeenCalledWith('Chapter 3', null);
|
|
73
|
+
});
|
|
74
|
+
});
|
package/src/types/player.ts
CHANGED
|
@@ -279,8 +279,16 @@ export interface PlayerCommands {
|
|
|
279
279
|
setTrack(type: 'video' | 'audio' | 'sub', trackId: number): void;
|
|
280
280
|
|
|
281
281
|
// PiP
|
|
282
|
-
/**
|
|
283
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Enter Picture-in-Picture mode.
|
|
284
|
+
*
|
|
285
|
+
* `chapterTitle` and `progressPct` are shown in the PiP notification.
|
|
286
|
+
* They are optional HERE, but the native TurboModule method takes two
|
|
287
|
+
* arguments and TurboModule enforces its arity — so the bridge call
|
|
288
|
+
* always passes two, never zero. See `enterPip` in the command
|
|
289
|
+
* implementation below.
|
|
290
|
+
*/
|
|
291
|
+
enterPip(chapterTitle?: string | null, progressPct?: string | null): void;
|
|
284
292
|
/** Exit PiP by bringing the activity to the front. */
|
|
285
293
|
exitPip(): void;
|
|
286
294
|
/** Exit PiP and finish the activity. */
|
|
@@ -685,9 +693,18 @@ function buildCommands(): PlayerCommands {
|
|
|
685
693
|
getMpvPlayerModule().setTrack(type, trackId);
|
|
686
694
|
},
|
|
687
695
|
|
|
688
|
-
enterPip: () => {
|
|
689
|
-
dlog('commands.enterPip()');
|
|
690
|
-
|
|
696
|
+
enterPip: (chapterTitle, progressPct) => {
|
|
697
|
+
dlog('commands.enterPip(', chapterTitle, ',', progressPct, ')');
|
|
698
|
+
// The native method has arity 2 and TurboModule ENFORCES it, so
|
|
699
|
+
// this call must always pass two arguments. Passing zero threw:
|
|
700
|
+
//
|
|
701
|
+
// Exception in HostFunction: TurboModule method "enterPip"
|
|
702
|
+
// called with 0 arguments (expected argument count: 2)
|
|
703
|
+
//
|
|
704
|
+
// The Kotlin side is nullable, so `null` is the right "not
|
|
705
|
+
// supplied" value — the native falls back to a title and a
|
|
706
|
+
// progress string of its own.
|
|
707
|
+
getMpvPlayerModule().enterPip(chapterTitle ?? null, progressPct ?? null);
|
|
691
708
|
},
|
|
692
709
|
exitPip: () => {
|
|
693
710
|
dlog('commands.exitPip()');
|