@simba-dev/react-native-media-player 1.9.0 → 1.9.1
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.9.
|
|
3
|
+
"version": "1.9.1",
|
|
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",
|
|
@@ -300,6 +300,27 @@ const OBSERVED_PROPERTIES: readonly string[] = [
|
|
|
300
300
|
'paused-for-cache',
|
|
301
301
|
'cache-buffering-state',
|
|
302
302
|
'demuxer-cache-state',
|
|
303
|
+
// V19 W8.3.1 — `mute` was MISSING from this list, and its absence was
|
|
304
|
+
// invisible in every test because the whole emitter is mocked.
|
|
305
|
+
//
|
|
306
|
+
// `PlayerState.isMuted` is documented and written as
|
|
307
|
+
// "`onPropertyChanged('mute')` + hydration" (src/types/player.ts:29),
|
|
308
|
+
// and `applyPlayerEvent` really does handle `case 'mute'`. But mpv
|
|
309
|
+
// only emits PROPERTY_CHANGE for names passed to
|
|
310
|
+
// `mpv_observe_property` — and `mute` was not one of them. So
|
|
311
|
+
// `commands.setMuted(true)` muted the audio while no event ever
|
|
312
|
+
// reached JS, `state.isMuted` stayed `false`, and a mute button
|
|
313
|
+
// rendered from that state looked completely inert: the glyph never
|
|
314
|
+
// changed, the label never changed, and the volume slider kept
|
|
315
|
+
// showing the real level.
|
|
316
|
+
//
|
|
317
|
+
// Measured on device (emulator-5554) with SIMBA W8.3: tapping "Mute"
|
|
318
|
+
// left the accessible label reading "Mute" and the slider reading
|
|
319
|
+
// "Volume, 100 percent". The command was correct; the OBSERVATION
|
|
320
|
+
// was missing. Same class of defect as the `seekable` gap above —
|
|
321
|
+
// the command surface and the state surface have to be wired
|
|
322
|
+
// separately, and wiring one does not wire the other.
|
|
323
|
+
'mute',
|
|
303
324
|
];
|
|
304
325
|
|
|
305
326
|
/**
|
|
@@ -626,6 +647,33 @@ export function PlayerProvider({
|
|
|
626
647
|
console.warn('[simba-player] seekable seed failed:', e);
|
|
627
648
|
}
|
|
628
649
|
|
|
650
|
+
// ── 2c. Seed the `mute` LEVEL too (same reasoning as `seekable`) ───
|
|
651
|
+
//
|
|
652
|
+
// `mute` is edge-triggered for the same reason `seekable` is: mpv
|
|
653
|
+
// fires PROPERTY_CHANGE when the flag CHANGES, so a provider that
|
|
654
|
+
// mounts while the player is already muted never learns it from the
|
|
655
|
+
// stream. `hydratePlayerState` covers a cold start, but not a
|
|
656
|
+
// provider mounted mid-session in a second React root.
|
|
657
|
+
//
|
|
658
|
+
// Reading it here closes that gap, and it is a cheap boolean.
|
|
659
|
+
try {
|
|
660
|
+
const raw = bridge.getProperty('mute');
|
|
661
|
+
if (raw === 'true' || raw === 'false') {
|
|
662
|
+
const isMuted = raw === 'true';
|
|
663
|
+
if (isMuted !== stateRef.current.isMuted) {
|
|
664
|
+
const seeded: PlayerState = {
|
|
665
|
+
...stateRef.current,
|
|
666
|
+
isMuted,
|
|
667
|
+
};
|
|
668
|
+
stateRef.current = seeded;
|
|
669
|
+
setState(seeded);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
} catch (e) {
|
|
673
|
+
// eslint-disable-next-line no-console
|
|
674
|
+
console.warn('[simba-player] mute seed failed:', e);
|
|
675
|
+
}
|
|
676
|
+
|
|
629
677
|
// ── 3. 1Hz position/duration poll ───────────────────────────────────
|
|
630
678
|
// Both `getPosition` and `getDuration` are sync React methods
|
|
631
679
|
// on the bridge, so the poll doesn't queue microtasks. We
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
useRenderControls,
|
|
35
35
|
} from '../PlayerProvider';
|
|
36
36
|
import { DEFAULT_PLAYER_CONFIG, DEFAULT_THEME } from '../../types/config';
|
|
37
|
-
import { usePlayerProgress
|
|
37
|
+
import {usePlayer, usePlayerProgress} from '../../types/player';
|
|
38
38
|
|
|
39
39
|
// Helper to clear all bridge mock call counts between tests.
|
|
40
40
|
function clearBridgeMocks() {
|
|
@@ -307,20 +307,81 @@ describe('mpv property observation', () => {
|
|
|
307
307
|
NativeModules.MpvPlayerModule.observeProperty as jest.Mock
|
|
308
308
|
).mock.calls.map((call: unknown[]) => call[0]);
|
|
309
309
|
|
|
310
|
-
// These
|
|
310
|
+
// These are the ones that are invisible until they are wrong:
|
|
311
311
|
// nothing polls them, so a missing registration is silent.
|
|
312
|
+
//
|
|
313
|
+
// `mute` is in this group for a measured reason. `PlayerState
|
|
314
|
+
// .isMuted` is documented as "`onPropertyChanged('mute')` +
|
|
315
|
+
// hydration" and `applyPlayerEvent` really does handle
|
|
316
|
+
// `case 'mute'` — but mpv only emits PROPERTY_CHANGE for names
|
|
317
|
+
// passed to `mpv_observe_property`, and `mute` was not one of them.
|
|
318
|
+
// So `commands.setMuted(true)` muted the audio while no event ever
|
|
319
|
+
// reached JS, `state.isMuted` stayed `false`, and a mute button
|
|
320
|
+
// rendered from that state looked inert: the glyph never changed
|
|
321
|
+
// and the label never changed. Found on device (emulator-5554)
|
|
322
|
+
// with SIMBA W8.3 — tapping "Mute" left the accessible label
|
|
323
|
+
// reading "Mute".
|
|
324
|
+
//
|
|
325
|
+
// Hydration did not save it: `hydratePlayerState` reads
|
|
326
|
+
// `getMuted()` once, which covers a cold start but not a provider
|
|
327
|
+
// that mounts mid-session. Hence the separate level seed as well.
|
|
312
328
|
expect(observed).toEqual(
|
|
313
329
|
expect.arrayContaining([
|
|
314
330
|
'seekable',
|
|
315
331
|
'seeking',
|
|
316
332
|
'paused-for-cache',
|
|
317
333
|
'demuxer-cache-state',
|
|
334
|
+
'mute',
|
|
318
335
|
]),
|
|
319
336
|
);
|
|
320
337
|
|
|
321
338
|
await unmount();
|
|
322
339
|
});
|
|
323
340
|
|
|
341
|
+
it('seeds `mute` as a LEVEL at mount, not only from the event stream', async () => {
|
|
342
|
+
// SPEC invariant I10: an edge-triggered event is not a level. mpv
|
|
343
|
+
// fires PROPERTY_CHANGE when `mute` CHANGES, so a provider mounted
|
|
344
|
+
// while the player is already muted never sees the event — the same
|
|
345
|
+
// gap that left `seekable` stuck at its default until W7 read it
|
|
346
|
+
// once at mount.
|
|
347
|
+
//
|
|
348
|
+
// The test emits NO event and still expects the correct value, which
|
|
349
|
+
// is the only shape that proves a SEED exists. A test that emits
|
|
350
|
+
// the event would pass whether or not the seed is there.
|
|
351
|
+
clearBridgeMocks();
|
|
352
|
+
(NativeModules.MpvPlayerModule.getProperty as jest.Mock).mockImplementation(
|
|
353
|
+
(name: string) => (name === 'mute' ? 'true' : 'null'),
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const { result, unmount } = await renderHook(() => usePlayer(), {
|
|
357
|
+
wrapper,
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
expect(result.current.state.isMuted).toBe(true);
|
|
361
|
+
|
|
362
|
+
await unmount();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('does not coerce a non-boolean `mute` property to false', async () => {
|
|
366
|
+
// The bridge serialises MPV_FORMAT_FLAG to the JSON literals
|
|
367
|
+
// `true` / `false`. Anything else — "null" for an unavailable
|
|
368
|
+
// property, "" for the NOOP bridge — is not a value, and coercing it
|
|
369
|
+
// to `false` would silently claim the player is unmuted when it may
|
|
370
|
+
// not be. This is the same guard the `seekable` seed has.
|
|
371
|
+
clearBridgeMocks();
|
|
372
|
+
(NativeModules.MpvPlayerModule.getProperty as jest.Mock).mockImplementation(
|
|
373
|
+
() => 'null',
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
const { result, unmount } = await renderHook(() => usePlayer(), {
|
|
377
|
+
wrapper,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
expect(result.current.state.isMuted).toBe(false);
|
|
381
|
+
|
|
382
|
+
await unmount();
|
|
383
|
+
});
|
|
384
|
+
|
|
324
385
|
it('observes the properties that back the polled events too', async () => {
|
|
325
386
|
// Lower latency than the 1 Hz poll, and `pause` / `eof-reached` are
|
|
326
387
|
// only reachable this way for a state change that happens between
|