@simba-dev/react-native-media-player 1.20.0 → 1.21.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.
|
@@ -2260,12 +2260,23 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2260
2260
|
*
|
|
2261
2261
|
* @param chapterTitle Optional — current chapter title shown in PiP notification.
|
|
2262
2262
|
* @param progressPct Optional — progress percentage string like "45 %".
|
|
2263
|
+
* @return true when the OS accepted the Picture-in-Picture request,
|
|
2264
|
+
* false when it refused it (no activity, SDK too old, PiP not
|
|
2265
|
+
* permitted, or the call threw). The caller MUST NOT assume
|
|
2266
|
+
* PiP is up just because it asked for it.
|
|
2263
2267
|
*/
|
|
2264
2268
|
@ReactMethod
|
|
2265
2269
|
@Override
|
|
2266
|
-
override fun enterPip(chapterTitle: String?, progressPct: String?) {
|
|
2270
|
+
override fun enterPip(chapterTitle: String?, progressPct: String?): Boolean {
|
|
2267
2271
|
val activity = getCurrentActivity()
|
|
2268
|
-
|
|
2272
|
+
// The two refusals below are ANSWERED, not swallowed. The caller
|
|
2273
|
+
// hides its fullscreen chrome when PiP is up, so a request that
|
|
2274
|
+
// quietly did nothing left the app in "PiP" mode with no chrome
|
|
2275
|
+
// and no way back. `false` tells it to keep the chrome.
|
|
2276
|
+
if (activity == null || android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) {
|
|
2277
|
+
Log.w(TAG, "[PlaybackTrace][Bridge][enterPip] refused: no activity or SDK < N")
|
|
2278
|
+
return false
|
|
2279
|
+
}
|
|
2269
2280
|
// v1.9.3 — SPEC invariant I7 (a TS signature must agree with the
|
|
2270
2281
|
// native reality it forwards to).
|
|
2271
2282
|
//
|
|
@@ -2317,7 +2328,14 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2317
2328
|
// animate from. That degrades to the no-hint behaviour, which costs a
|
|
2318
2329
|
// black transition but never a distorted one.
|
|
2319
2330
|
val sourceRect = PlayerSurface.boundsInWindow()
|
|
2320
|
-
try
|
|
2331
|
+
// `return try`, not a bare `try`. A `try`/`catch` in STATEMENT
|
|
2332
|
+
// position is not this function's return value in Kotlin — not
|
|
2333
|
+
// even as the last statement of a function with a non-`Unit`
|
|
2334
|
+
// return type. The compiler says "Missing return statement",
|
|
2335
|
+
// which is precisely what it said the first time round. Only an
|
|
2336
|
+
// EXPRESSION `try` produces a value, and the branches inside it
|
|
2337
|
+
// are the ones that carry the OS's answer.
|
|
2338
|
+
return try {
|
|
2321
2339
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
2322
2340
|
val pipParams = com.simba.player.PipManager.buildPipParams(
|
|
2323
2341
|
context = activity,
|
|
@@ -2326,19 +2344,36 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2326
2344
|
chapterTitle = title,
|
|
2327
2345
|
progressPercentage = pct,
|
|
2328
2346
|
)
|
|
2347
|
+
// `enterPictureInPictureMode` ANSWERS whether the OS
|
|
2348
|
+
// accepted the request, and the answer was being
|
|
2349
|
+
// discarded. It is the only authority on this: the app
|
|
2350
|
+
// hides its chrome when PiP is up, so "we think it worked"
|
|
2351
|
+
// is not good enough.
|
|
2329
2352
|
activity.enterPictureInPictureMode(pipParams)
|
|
2330
2353
|
} else {
|
|
2331
2354
|
// API 24–25 support PiP but not PictureInPictureParams.
|
|
2355
|
+
// The no-arg overload returns Unit, so those versions
|
|
2356
|
+
// have no answer to relay; the PiP mode-change event is
|
|
2357
|
+
// the only confirmation available there.
|
|
2332
2358
|
activity.enterPictureInPictureMode()
|
|
2359
|
+
true
|
|
2333
2360
|
}
|
|
2334
2361
|
} catch (throwable: Throwable) {
|
|
2335
2362
|
// P1: the previous `catch (_: IllegalStateException)` was
|
|
2336
2363
|
// too narrow. `enterPictureInPictureMode` can also throw
|
|
2337
2364
|
// `IllegalArgumentException` (bad params), `RuntimeException`
|
|
2338
2365
|
// (OEM customisations), or `SecurityException` (PiP not
|
|
2339
|
-
// permitted). We log the actual cause and
|
|
2340
|
-
//
|
|
2366
|
+
// permitted). We log the actual cause, and the `false` below
|
|
2367
|
+
// tells the JS side that PiP did NOT happen.
|
|
2368
|
+
//
|
|
2369
|
+
// (This block used to say a "5 s recovery timer in
|
|
2370
|
+
// `VideoPipAdapter`" would take over. There is no
|
|
2371
|
+
// `VideoPipAdapter` in this repository — it was removed with
|
|
2372
|
+
// the V12 single-activity architecture — so nothing was
|
|
2373
|
+
// taking over, and a refused request simply stranded the app
|
|
2374
|
+
// with no chrome. The `false` return is the recovery.)
|
|
2341
2375
|
Log.w(TAG, "[PlaybackTrace][Bridge][enterPip:threw]", throwable)
|
|
2376
|
+
false
|
|
2342
2377
|
}
|
|
2343
2378
|
}
|
|
2344
2379
|
|
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.21.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",
|
|
@@ -503,8 +503,15 @@ export interface MpvPlayerModuleBridge {
|
|
|
503
503
|
setConfig(configJson: string): Promise<number>;
|
|
504
504
|
|
|
505
505
|
// ── Picture-in-Picture ─────────────────────────────────────────────────
|
|
506
|
-
/**
|
|
507
|
-
|
|
506
|
+
/**
|
|
507
|
+
* Enter PiP mode; optional chapter title + progress percent for notification.
|
|
508
|
+
*
|
|
509
|
+
* Returns whether the OS accepted the request. `false` means PiP did NOT
|
|
510
|
+
* happen — the native side has the answer (`enterPictureInPictureMode`
|
|
511
|
+
* returns it) and the caller needs it, because a caller that hides its
|
|
512
|
+
* chrome on a refused request has no way to bring it back.
|
|
513
|
+
*/
|
|
514
|
+
enterPip(chapterTitle?: string | null, progressPct?: string | null): boolean;
|
|
508
515
|
/** Exit PiP by bringing the activity to the front. */
|
|
509
516
|
exitPip(): void;
|
|
510
517
|
/** Exit PiP and finish the activity. */
|
|
@@ -745,9 +752,13 @@ const NOOP_BRIDGE: MpvPlayerModuleBridge = {
|
|
|
745
752
|
},
|
|
746
753
|
|
|
747
754
|
// PiP
|
|
748
|
-
enterPip: (_chapterTitle?: string, _progressPct?: string) => {
|
|
755
|
+
enterPip: (_chapterTitle?: string | null, _progressPct?: string | null) => {
|
|
749
756
|
void _chapterTitle;
|
|
750
757
|
void _progressPct;
|
|
758
|
+
// This stub does nothing, so the honest answer is `false` — PiP did
|
|
759
|
+
// not happen. Returning `true` here would tell a caller to hide its
|
|
760
|
+
// chrome for a PiP window that will never exist.
|
|
761
|
+
return false;
|
|
751
762
|
},
|
|
752
763
|
exitPip: () => {},
|
|
753
764
|
exitPipAndFinish: () => {},
|
|
@@ -320,7 +320,16 @@ export interface Spec extends TurboModule {
|
|
|
320
320
|
// here said "you may call this with no arguments", which is exactly
|
|
321
321
|
// the licence the zero-argument call site took — and the crash it
|
|
322
322
|
// produced was an "expected argument count: 2" rejection.
|
|
323
|
-
|
|
323
|
+
//
|
|
324
|
+
// The return type is `boolean`, and it is the OS's own answer to
|
|
325
|
+
// "did PiP happen?". `Activity.enterPictureInPictureMode` returns
|
|
326
|
+
// exactly that, and the previous `void` threw the answer away: a
|
|
327
|
+
// REFUSED request (no activity, PiP not permitted, bad params) then
|
|
328
|
+
// looked identical to a successful one, so a caller that hides its
|
|
329
|
+
// chrome on the strength of a successful request was left with no
|
|
330
|
+
// chrome and no way back. Declaring the answer here is what lets it
|
|
331
|
+
// survive codegen.
|
|
332
|
+
enterPip(chapterTitle: string | null, progressPct: string | null): boolean;
|
|
324
333
|
exitPip(): void;
|
|
325
334
|
exitPipAndFinish(): void;
|
|
326
335
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PiP command must RELAY the OS's answer.
|
|
3
|
+
*
|
|
4
|
+
* ## The defect
|
|
5
|
+
*
|
|
6
|
+
* The native `enterPip` returned `Unit` and swallowed every failure:
|
|
7
|
+
*
|
|
8
|
+
* - no activity → silent `return`
|
|
9
|
+
* - SDK < N → silent `return`
|
|
10
|
+
* - `enterPictureInPictureMode` returned false → the boolean was DISCARDED
|
|
11
|
+
* - it threw → caught, logged, swallowed
|
|
12
|
+
*
|
|
13
|
+
* A REFUSED PiP request was therefore indistinguishable from a successful
|
|
14
|
+
* one, at the JS boundary.
|
|
15
|
+
*
|
|
16
|
+
* That matters because of what the caller does with the request. The app
|
|
17
|
+
* suppresses its fullscreen chrome when PiP is up, so a refused request
|
|
18
|
+
* that went unreported left the app in "PiP" mode with no transport bar, no
|
|
19
|
+
* top bar, and no way out — the same latch the unmount bug produced,
|
|
20
|
+
* reached by a different road.
|
|
21
|
+
*
|
|
22
|
+
* `Activity.enterPictureInPictureMode(PictureInPictureParams)` returns the
|
|
23
|
+
* OS's own answer, so the fix is to stop throwing it away.
|
|
24
|
+
*
|
|
25
|
+
* ## What this asserts
|
|
26
|
+
*
|
|
27
|
+
* The RESULT, not just that the bridge was called. A test that only checked
|
|
28
|
+
* "enterPip was called" would pass with the old `void` contract and the
|
|
29
|
+
* bug would survive — which is exactly the mistake the arity test
|
|
30
|
+
* (`player.pipArity.test.tsx`) was written to avoid.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import {NativeModules} from 'react-native';
|
|
34
|
+
import {renderHook} from '@testing-library/react-native';
|
|
35
|
+
import {usePlayer} from '../player';
|
|
36
|
+
|
|
37
|
+
function enterPipMock(): jest.Mock {
|
|
38
|
+
return (NativeModules.MpvPlayerModule as unknown as Record<string, jest.Mock>)
|
|
39
|
+
.enterPip;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('commands.enterPip — the native answer is relayed', () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
enterPipMock().mockClear();
|
|
45
|
+
// The shared setup mock answers `true` (a successful entry). Each
|
|
46
|
+
// test that cares sets the answer it needs.
|
|
47
|
+
enterPipMock().mockReturnValue(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('returns true when the OS accepted the request', async () => {
|
|
51
|
+
const {result} = await renderHook(() => usePlayer());
|
|
52
|
+
|
|
53
|
+
expect(result.current.commands.enterPip()).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('returns false when the OS REFUSED the request', async () => {
|
|
57
|
+
// No activity, PiP not permitted, bad params — the native side now
|
|
58
|
+
// answers `false` instead of swallowing the failure.
|
|
59
|
+
enterPipMock().mockReturnValue(false);
|
|
60
|
+
const {result} = await renderHook(() => usePlayer());
|
|
61
|
+
|
|
62
|
+
expect(result.current.commands.enterPip()).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('does not swallow a refusal — the result is the caller\'s only signal', async () => {
|
|
66
|
+
enterPipMock().mockReturnValue(false);
|
|
67
|
+
const {result} = await renderHook(() => usePlayer());
|
|
68
|
+
|
|
69
|
+
const answer = result.current.commands.enterPip();
|
|
70
|
+
|
|
71
|
+
// A falsy-but-present answer is what the caller branches on. A
|
|
72
|
+
// `undefined` (the old `void` contract) is indistinguishable from
|
|
73
|
+
// "the native module is missing", so the assertion is on `false`
|
|
74
|
+
// specifically, not on falsiness.
|
|
75
|
+
expect(answer).not.toBeUndefined();
|
|
76
|
+
expect(answer).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('still calls the bridge with TWO arguments while answering', async () => {
|
|
80
|
+
const {result} = await renderHook(() => usePlayer());
|
|
81
|
+
result.current.commands.enterPip('Chapter 3', '45 %');
|
|
82
|
+
|
|
83
|
+
const enterPip = enterPipMock();
|
|
84
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
85
|
+
expect(enterPip).toHaveBeenCalledWith('Chapter 3', '45 %');
|
|
86
|
+
});
|
|
87
|
+
});
|
package/src/types/player.ts
CHANGED
|
@@ -287,8 +287,18 @@ export interface PlayerCommands {
|
|
|
287
287
|
* arguments and TurboModule enforces its arity — so the bridge call
|
|
288
288
|
* always passes two, never zero. See `enterPip` in the command
|
|
289
289
|
* implementation below.
|
|
290
|
+
*
|
|
291
|
+
* Returns whether the OS ACCEPTED the request. This is not a nicety: the
|
|
292
|
+
* caller suppresses its fullscreen chrome when PiP is up, so a request
|
|
293
|
+
* that was refused — no activity, PiP not permitted, a bad `PictureInPictureParams`
|
|
294
|
+
* — and went unreported left the app in "PiP" mode with no chrome and no
|
|
295
|
+
* way back. The native `enterPictureInPictureMode` knows the answer, so
|
|
296
|
+
* it is relayed instead of guessed.
|
|
297
|
+
*
|
|
298
|
+
* `false` means PiP did NOT happen. It does not mean the app is in a bad
|
|
299
|
+
* state: the caller keeps its chrome, exactly as before the request.
|
|
290
300
|
*/
|
|
291
|
-
enterPip(chapterTitle?: string | null, progressPct?: string | null):
|
|
301
|
+
enterPip(chapterTitle?: string | null, progressPct?: string | null): boolean;
|
|
292
302
|
/** Exit PiP by bringing the activity to the front. */
|
|
293
303
|
exitPip(): void;
|
|
294
304
|
/** Exit PiP and finish the activity. */
|
|
@@ -704,7 +714,17 @@ function buildCommands(): PlayerCommands {
|
|
|
704
714
|
// The Kotlin side is nullable, so `null` is the right "not
|
|
705
715
|
// supplied" value — the native falls back to a title and a
|
|
706
716
|
// progress string of its own.
|
|
707
|
-
|
|
717
|
+
//
|
|
718
|
+
// The result is the OS's own answer to "did PiP happen?". It used
|
|
719
|
+
// to be dropped, which meant a REFUSED request (no activity, PiP
|
|
720
|
+
// not permitted, a bad PictureInPictureParams) was indistinguishable
|
|
721
|
+
// from a successful one — and a caller that suppresses its chrome
|
|
722
|
+
// on the strength of a successful request was then stuck with no
|
|
723
|
+
// chrome and no way back. Relaying the answer is the whole fix.
|
|
724
|
+
return getMpvPlayerModule().enterPip(
|
|
725
|
+
chapterTitle ?? null,
|
|
726
|
+
progressPct ?? null,
|
|
727
|
+
);
|
|
708
728
|
},
|
|
709
729
|
exitPip: () => {
|
|
710
730
|
dlog('commands.exitPip()');
|