@simba-dev/react-native-media-player 1.9.1 → 1.9.2
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 +1 -1
- package/src/types/__tests__/player.test.tsx +104 -0
- package/src/types/player.ts +48 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
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",
|
|
@@ -431,6 +431,110 @@ describe('usePlayer (inside PlayerProvider)', () => {
|
|
|
431
431
|
expect(result.current.state.isPlaying).toBe(true);
|
|
432
432
|
});
|
|
433
433
|
|
|
434
|
+
// ── The mute flag arrives as a STRING ─────────────────────────────────
|
|
435
|
+
//
|
|
436
|
+
// `applyPlayerEvent`'s `mute` case used to be
|
|
437
|
+
// `isMuted: Boolean(value)`. mpv serialises MPV_FORMAT_FLAG to the
|
|
438
|
+
// JSON literals `true` / `false`, which reach JS as the STRINGS
|
|
439
|
+
// `"true"` / `"false"`. Every non-empty string is truthy, so
|
|
440
|
+
// `Boolean("false") === true` and the state was INVERTED on every
|
|
441
|
+
// mute event.
|
|
442
|
+
//
|
|
443
|
+
// Measured on device (emulator-5554, SIMBA W8.3 + lib 1.9.1): native
|
|
444
|
+
// logged `name=mute value=false`, the bridge dispatched `value=false`,
|
|
445
|
+
// and the transport still rendered "Unmute" on an audible player.
|
|
446
|
+
//
|
|
447
|
+
// These tests drive the REAL event path through the provider, so they
|
|
448
|
+
// cover the reducer as well as the wiring.
|
|
449
|
+
|
|
450
|
+
it('reads the mute flag string "false" as FALSE, not as truthy', async () => {
|
|
451
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
452
|
+
<PlayerProvider>{children}</PlayerProvider>
|
|
453
|
+
);
|
|
454
|
+
const { result } = await renderHook(() => usePlayer(), { wrapper });
|
|
455
|
+
|
|
456
|
+
const listeners = subs.handlers.get('onPropertyChanged') ?? [];
|
|
457
|
+
expect(listeners.length).toBeGreaterThan(0);
|
|
458
|
+
|
|
459
|
+
await act(async () => {
|
|
460
|
+
for (const l of listeners) {
|
|
461
|
+
l({property: 'mute', value: 'false'});
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// The default is already false, so this is the state that a
|
|
466
|
+
// `Boolean()` coercion would have flipped.
|
|
467
|
+
expect(result.current.state.isMuted).toBe(false);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('reads the mute flag string "true" as TRUE', async () => {
|
|
471
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
472
|
+
<PlayerProvider>{children}</PlayerProvider>
|
|
473
|
+
);
|
|
474
|
+
const { result } = await renderHook(() => usePlayer(), { wrapper });
|
|
475
|
+
|
|
476
|
+
const listeners = subs.handlers.get('onPropertyChanged') ?? [];
|
|
477
|
+
await act(async () => {
|
|
478
|
+
for (const l of listeners) {
|
|
479
|
+
l({property: 'mute', value: 'true'});
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
expect(result.current.state.isMuted).toBe(true);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it('also accepts a real boolean mute flag', async () => {
|
|
487
|
+
// `getMuted()` on the bridge returns an actual boolean while the
|
|
488
|
+
// event payload is a string. Both feed the same field, so both must
|
|
489
|
+
// parse.
|
|
490
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
491
|
+
<PlayerProvider>{children}</PlayerProvider>
|
|
492
|
+
);
|
|
493
|
+
const { result } = await renderHook(() => usePlayer(), { wrapper });
|
|
494
|
+
|
|
495
|
+
const listeners = subs.handlers.get('onPropertyChanged') ?? [];
|
|
496
|
+
await act(async () => {
|
|
497
|
+
for (const l of listeners) {
|
|
498
|
+
l({property: 'mute', value: true});
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
expect(result.current.state.isMuted).toBe(true);
|
|
502
|
+
|
|
503
|
+
await act(async () => {
|
|
504
|
+
for (const l of listeners) {
|
|
505
|
+
l({property: 'mute', value: false});
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
expect(result.current.state.isMuted).toBe(false);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it('leaves the mute state alone for an unreadable flag value', async () => {
|
|
512
|
+
// `"null"` is what the bridge returns for an unavailable property
|
|
513
|
+
// and `""` comes from the NOOP bridge. Neither is a boolean, and
|
|
514
|
+
// coercing them would report a state the player is not in — the
|
|
515
|
+
// same rule the `seekable` level seed follows.
|
|
516
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
517
|
+
<PlayerProvider>{children}</PlayerProvider>
|
|
518
|
+
);
|
|
519
|
+
const { result } = await renderHook(() => usePlayer(), { wrapper });
|
|
520
|
+
|
|
521
|
+
const listeners = subs.handlers.get('onPropertyChanged') ?? [];
|
|
522
|
+
await act(async () => {
|
|
523
|
+
for (const l of listeners) {
|
|
524
|
+
l({property: 'mute', value: 'true'});
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
expect(result.current.state.isMuted).toBe(true);
|
|
528
|
+
|
|
529
|
+
await act(async () => {
|
|
530
|
+
for (const l of listeners) {
|
|
531
|
+
l({property: 'mute', value: 'null'});
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
// Still muted — an unreadable value must not silently unmute.
|
|
535
|
+
expect(result.current.state.isMuted).toBe(true);
|
|
536
|
+
});
|
|
537
|
+
|
|
434
538
|
it('updates state when an onError event fires', async () => {
|
|
435
539
|
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
436
540
|
<PlayerProvider>{children}</PlayerProvider>
|
package/src/types/player.ts
CHANGED
|
@@ -969,6 +969,38 @@ export function parseMetadata(
|
|
|
969
969
|
* unchanged. For events that touch both, both are updated. This is
|
|
970
970
|
* the canonical V13 "split-context" pattern.
|
|
971
971
|
*/
|
|
972
|
+
/**
|
|
973
|
+
* Parse an mpv FLAG value into a boolean, or `null` when it is not one.
|
|
974
|
+
*
|
|
975
|
+
* mpv serialises `MPV_FORMAT_FLAG` to the JSON literals `true` /
|
|
976
|
+
* `false`, which reach JS as the STRINGS `"true"` / `"false"`.
|
|
977
|
+
* `Boolean("false")` is `true`, so any flag read with `Boolean()` is
|
|
978
|
+
* silently inverted — the `mute` case did exactly that and shipped a
|
|
979
|
+
* mute control that reported the opposite of reality.
|
|
980
|
+
*
|
|
981
|
+
* A real boolean is accepted too, because `getMuted()` on the bridge
|
|
982
|
+
* returns an actual `boolean` while the event payload is a string, and
|
|
983
|
+
* the two feed the same field.
|
|
984
|
+
*
|
|
985
|
+
* Anything else — `"null"` for an unavailable property, `""` from the
|
|
986
|
+
* NOOP bridge, `undefined` — is not a value. The caller leaves the
|
|
987
|
+
* field unchanged rather than coercing it, because guessing here would
|
|
988
|
+
* report a state the player is not in.
|
|
989
|
+
*/
|
|
990
|
+
function parseMpvFlag(value: unknown): boolean | null {
|
|
991
|
+
if (typeof value === 'boolean') return value;
|
|
992
|
+
if (value === 'true') return true;
|
|
993
|
+
if (value === 'false') return false;
|
|
994
|
+
return null;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/** Apply a `mute` flag event, leaving the field alone if unreadable. */
|
|
998
|
+
function applyMuteFlag(state: PlayerState, value: unknown): PlayerState {
|
|
999
|
+
const isMuted = parseMpvFlag(value);
|
|
1000
|
+
if (isMuted === null || isMuted === state.isMuted) return state;
|
|
1001
|
+
return { ...state, isMuted };
|
|
1002
|
+
}
|
|
1003
|
+
|
|
972
1004
|
export function applyPlayerEvent(
|
|
973
1005
|
state: PlayerState,
|
|
974
1006
|
progress: PlayerProgress,
|
|
@@ -1025,7 +1057,22 @@ export function applyPlayerEvent(
|
|
|
1025
1057
|
case 'volume':
|
|
1026
1058
|
return { state: { ...state, volume: Number(value) }, progress };
|
|
1027
1059
|
case 'mute':
|
|
1028
|
-
|
|
1060
|
+
// A FLAG property arrives as the JSON literal `"true"` /
|
|
1061
|
+
// `"false"` — a STRING, not a boolean. `Boolean("false")` is
|
|
1062
|
+
// `true`, because every non-empty string is truthy, so the
|
|
1063
|
+
// obvious one-liner INVERTED the state: every mute event
|
|
1064
|
+
// reported the opposite of what mpv said.
|
|
1065
|
+
//
|
|
1066
|
+
// Measured on device (emulator-5554, SIMBA W8.3 + lib 1.9.1):
|
|
1067
|
+
// native logged `name=mute value=false` and the bridge
|
|
1068
|
+
// dispatched `value=false`, yet the app's transport rendered
|
|
1069
|
+
// "Unmute" while the player was audible. The mute control read
|
|
1070
|
+
// as permanently inverted.
|
|
1071
|
+
//
|
|
1072
|
+
// Parsed explicitly, and anything unrecognised leaves the
|
|
1073
|
+
// field alone rather than guessing — the same rule the
|
|
1074
|
+
// `seekable` level seed and `hydratePlayerState` follow.
|
|
1075
|
+
return { state: applyMuteFlag(state, value), progress };
|
|
1029
1076
|
case 'speed':
|
|
1030
1077
|
return { state: { ...state, speed: Number(value) }, progress };
|
|
1031
1078
|
case 'loop-file':
|