@simba-dev/react-native-media-player 1.8.4 → 1.9.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 +1 -1
- package/android/src/main/cpp/main.cpp +4 -10
- package/android/src/main/java/com/simba/player/mpv/MPVLib.kt +0 -4
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +7 -7
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +3 -5
- package/src/bridge/NativeMpvPlayer.ts +3 -1
- package/src/components/PlayerProvider.tsx +43 -0
- package/src/components/__tests__/PlayerProvider.test.tsx +105 -0
- package/src/types/__tests__/player.test.tsx +0 -1
- package/src/types/player.ts +9 -7
package/README.md
CHANGED
|
@@ -477,7 +477,7 @@ Every public export lives in [`src/index.ts`](./src/index.ts). The **V13+ surfac
|
|
|
477
477
|
|---|---|
|
|
478
478
|
| `PlayerState` | 20 fields: `isPlaying`, `title`, `artist`, `album`, `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `volume`, `isMuted`, `speed`, `loopMode`, `playlist`, `currentIndex`, `tracks`, `chapters`, `currentChapter`, `videoParams`, `error` |
|
|
479
479
|
| `PlayerProgress` | 7 fields: `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `cacheRanges`, `cacheFill` |
|
|
480
|
-
| `PlayerCommands` | 38 methods: `play`, `pause`, `seek`, `skipBackward`, `skipForward`, `togglePlayPause`, `stop`, `seekBy`, `seekToChapter`, `next`, `previous`, `setVolume`, `setMuted`, `toggleMute`, `setSpeed`, `setLoopMode`, `loadFile`, `loadPlaylist`, `playlistRemove`, `shuffle`, `clear`, `
|
|
480
|
+
| `PlayerCommands` | 38 methods: `play`, `pause`, `seek`, `skipBackward`, `skipForward`, `togglePlayPause`, `stop`, `seekBy`, `seekToChapter`, `next`, `previous`, `setVolume`, `setMuted`, `toggleMute`, `setSpeed`, `setLoopMode`, `loadFile`, `loadPlaylist`, `playlistRemove`, `shuffle`, `clear`, `cycleTrack`, `setTrack`, `enterPip`, `exitPip`, `exitPipAndFinish`, `setKeepScreenOn`, `setOrientation`, `setImmersive`, `setScreenBrightness`, `requestNotificationPermission`, `openPlayer`, `getLaunchParams`, `getProperty`, `setProperty`, `observeProperty`, `unobserveProperty`, `grantPersistablePermission`, `verifyContentUri` |
|
|
481
481
|
| `OpenPlayerOptions` | `{ uri, title, type: 'video' \| 'audio', startPositionMs? }` — the V13 `openPlayer` arg shape (replaces V11's positional args) |
|
|
482
482
|
| `LaunchParams` | `{ uri, title, type, startPositionMs }` — read from the activity via `useLaunchParams()` |
|
|
483
483
|
| `ContentKind` | `'video' \| 'audio' \| 'music' \| 'movie' \| 'podcast' \| 'live-tv' \| 'radio' \| 'audiobook' \| 'archive-audio' \| 'episode' \| 'video-file' \| string` |
|
|
@@ -753,16 +753,10 @@ Java_com_simba_player_mpv_MPVLib_nativePlaylistClear(
|
|
|
753
753
|
mpv_command(mpv, clearArgs);
|
|
754
754
|
}
|
|
755
755
|
|
|
756
|
-
//
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
JNIEnv *env, jclass, jlong nativePtr, jint trackId) {
|
|
761
|
-
NativeMpvReadLease lease(nativePtr);
|
|
762
|
-
if (!lease.valid()) return;
|
|
763
|
-
mpv_handle *mpv = lease.get();
|
|
764
|
-
mpv_set_property(mpv, "vid", MPV_FORMAT_INT64, &trackId);
|
|
765
|
-
}
|
|
756
|
+
// `nativeSelectTrack()` was REMOVED — it carried no track type, and it
|
|
757
|
+
// hardcoded mpv's "vid" property, so selecting a subtitle track retargeted
|
|
758
|
+
// the VIDEO track. `setTrack(type, trackId)` in MpvBridgeModule.kt routes to
|
|
759
|
+
// vid/aid/sid via `nativeSetPropertyString` instead.
|
|
766
760
|
|
|
767
761
|
// ── Filters ─────────────────────────────────────────────────────────────────
|
|
768
762
|
|
|
@@ -71,10 +71,6 @@ object MPVLib {
|
|
|
71
71
|
external fun nativePlaylistShuffle(nativePtr: Long)
|
|
72
72
|
external fun nativePlaylistClear(nativePtr: Long)
|
|
73
73
|
|
|
74
|
-
// ── Tracks ─────────────────────────────────────────────────────────────
|
|
75
|
-
|
|
76
|
-
external fun nativeSelectTrack(nativePtr: Long, trackId: Int)
|
|
77
|
-
|
|
78
74
|
// ── Properties ─────────────────────────────────────────────────────────
|
|
79
75
|
|
|
80
76
|
external fun nativeGetProperty(nativePtr: Long, name: String): String
|
|
@@ -813,13 +813,13 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
813
813
|
} catch (_: Exception) { "[]" }
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
816
|
+
/**
|
|
817
|
+
* `selectTrack(trackId)` was REMOVED. It carried no track type, and its
|
|
818
|
+
* native implementation hardcoded mpv's "vid" property, so selecting a
|
|
819
|
+
* subtitle retargeted the VIDEO track. Use `setTrack(type, trackId)`
|
|
820
|
+
* instead — it maps video/audio/sub to vid/aid/sid and handles disabling
|
|
821
|
+
* via a negative id.
|
|
822
|
+
*/
|
|
823
823
|
@ReactMethod
|
|
824
824
|
@Override
|
|
825
825
|
override fun setTrack(type: String, trackId: Double) {
|
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.9.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",
|
|
@@ -235,8 +235,9 @@ export interface MpvPlayerModuleBridge {
|
|
|
235
235
|
// ── Tracks ─────────────────────────────────────────────────────────────
|
|
236
236
|
/** Get the mpv track list as a JSON string. */
|
|
237
237
|
getTracks(): string;
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
// `selectTrack(trackId)` was REMOVED — it carried no track type, and its
|
|
239
|
+
// native implementation hardcoded mpv's "vid" property, so selecting a
|
|
240
|
+
// subtitle retargeted the VIDEO track. Use `setTrack(type, trackId)`.
|
|
240
241
|
/** Cycle to the next/previous track of the given type. */
|
|
241
242
|
cycleTrack(type: 'video' | 'audio' | 'sub'): void;
|
|
242
243
|
/** Set the active track for a type (trackId < 0 means "no"). */
|
|
@@ -482,9 +483,6 @@ const NOOP_BRIDGE: MpvPlayerModuleBridge = {
|
|
|
482
483
|
|
|
483
484
|
// Tracks
|
|
484
485
|
getTracks: () => '[]',
|
|
485
|
-
selectTrack: (_trackId: number) => {
|
|
486
|
-
void _trackId;
|
|
487
|
-
},
|
|
488
486
|
cycleTrack: (_type: 'video' | 'audio' | 'sub') => {
|
|
489
487
|
void _type;
|
|
490
488
|
},
|
|
@@ -78,7 +78,9 @@ export interface Spec extends TurboModule {
|
|
|
78
78
|
|
|
79
79
|
// ── Tracks ─────────────────────────────────────────────────────────────
|
|
80
80
|
getTracks(): string;
|
|
81
|
-
selectTrack(trackId
|
|
81
|
+
// `selectTrack(trackId)` was REMOVED — it carried no track type, and its
|
|
82
|
+
// native implementation hardcoded mpv's "vid" property, so selecting a
|
|
83
|
+
// subtitle retargeted the VIDEO track. Use `setTrack(type, trackId)`.
|
|
82
84
|
cycleTrack(type: string): void;
|
|
83
85
|
setTrack(type: string, trackId: number): void;
|
|
84
86
|
setTrackVisibility(trackType: string, visible: boolean): void;
|
|
@@ -583,6 +583,49 @@ export function PlayerProvider({
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
|
|
586
|
+
// ── 2b. Re-read the LEVEL-only progress fields ───────────────────────
|
|
587
|
+
//
|
|
588
|
+
// `seekable` is a LEVEL value that mpv delivers only as an EDGE:
|
|
589
|
+
// MPV_EVENT_PROPERTY_CHANGE is emitted once, at the instant the flag
|
|
590
|
+
// flips from false to true. Any provider that mounts — or remounts,
|
|
591
|
+
// e.g. in a second React root — after that flip never observes the
|
|
592
|
+
// event, so the field stays at DEFAULT_PROGRESS forever and the
|
|
593
|
+
// consumer's seek bar renders permanently disabled.
|
|
594
|
+
//
|
|
595
|
+
// Measured on device (Android 37): `onCacheState` — which changes
|
|
596
|
+
// continuously — reached JS 827 times, while `onSeekable` arrived
|
|
597
|
+
// ZERO times across both a cold start and an app restart, because by
|
|
598
|
+
// then the flag had already settled and mpv will not repeat it.
|
|
599
|
+
//
|
|
600
|
+
// So read the level once at mount. The event keeps driving updates
|
|
601
|
+
// afterwards; this only closes the gap for a provider that starts
|
|
602
|
+
// mid-session. Without it the only correct usage pattern is
|
|
603
|
+
// "subscribe strictly before loadFile", which no consumer can be
|
|
604
|
+
// asked to guarantee across activities.
|
|
605
|
+
try {
|
|
606
|
+
const raw = bridge.getProperty('seekable');
|
|
607
|
+
// The bridge serialises MPV_FORMAT_FLAG to the JSON literals
|
|
608
|
+
// `true` / `false` (property.cpp, appendNode). Anything else -
|
|
609
|
+
// "null" for an unavailable property, "" for the NOOP bridge -
|
|
610
|
+
// is not a value, and must not be coerced to false.
|
|
611
|
+
if (raw === 'true' || raw === 'false') {
|
|
612
|
+
const seekable = raw === 'true';
|
|
613
|
+
if (seekable !== progressRef.current.seekable) {
|
|
614
|
+
const seeded: PlayerProgress = {
|
|
615
|
+
...progressRef.current,
|
|
616
|
+
seekable,
|
|
617
|
+
};
|
|
618
|
+
progressRef.current = seeded;
|
|
619
|
+
setProgress(seeded);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
} catch (e) {
|
|
623
|
+
// Best-effort: a bridge without `getProperty` (or no live mpv
|
|
624
|
+
// instance yet) leaves the field to the event stream.
|
|
625
|
+
// eslint-disable-next-line no-console
|
|
626
|
+
console.warn('[simba-player] seekable seed failed:', e);
|
|
627
|
+
}
|
|
628
|
+
|
|
586
629
|
// ── 3. 1Hz position/duration poll ───────────────────────────────────
|
|
587
630
|
// Both `getPosition` and `getDuration` are sync React methods
|
|
588
631
|
// on the bridge, so the poll doesn't queue microtasks. We
|
|
@@ -379,3 +379,108 @@ describe('mpv property observation', () => {
|
|
|
379
379
|
await unmount();
|
|
380
380
|
});
|
|
381
381
|
});
|
|
382
|
+
|
|
383
|
+
// -- `seekable` is edge-only, so mount must read the level -----------------
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* mpv delivers `seekable` as a LEVEL value but only reports it as an
|
|
387
|
+
* EDGE: MPV_EVENT_PROPERTY_CHANGE fires once, at the instant the flag
|
|
388
|
+
* flips. A provider that mounts after that flip never sees the event.
|
|
389
|
+
*
|
|
390
|
+
* Measured on device, that meant `progress.seekable` stayed false
|
|
391
|
+
* forever and every consumer's seek bar rendered permanently disabled
|
|
392
|
+
* on ordinary seekable files. `onCacheState` — which changes
|
|
393
|
+
* continuously — arrived 827 times over the same window, which is what
|
|
394
|
+
* proved the subscription path itself was fine and isolated the fault
|
|
395
|
+
* to the missed edge.
|
|
396
|
+
*
|
|
397
|
+
* These tests pin the compensating level read. They use NO emitted
|
|
398
|
+
* event at all: the provider must know `seekable` on its own.
|
|
399
|
+
*/
|
|
400
|
+
describe('PlayerProvider seekable seeding', () => {
|
|
401
|
+
const seekableProp = (
|
|
402
|
+
NativeModules.MpvPlayerModule as unknown as {
|
|
403
|
+
getProperty: jest.Mock;
|
|
404
|
+
}
|
|
405
|
+
).getProperty;
|
|
406
|
+
|
|
407
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
408
|
+
<PlayerProvider>{children}</PlayerProvider>
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
beforeEach(() => {
|
|
412
|
+
clearBridgeMocks();
|
|
413
|
+
seekableProp.mockReturnValue('');
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
afterEach(() => {
|
|
417
|
+
seekableProp.mockReturnValue('');
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('reads seekable at mount even though no event was ever emitted', async () => {
|
|
421
|
+
// The regression: the flag is already true in mpv, but the edge was
|
|
422
|
+
// consumed before this provider existed.
|
|
423
|
+
seekableProp.mockImplementation((name: string) =>
|
|
424
|
+
name === 'seekable' ? 'true' : 'null',
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
const { result, unmount } = await renderHook(() => usePlayerProgress(), {
|
|
428
|
+
wrapper,
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
expect(result.current.seekable).toBe(true);
|
|
432
|
+
// And it must be read, not inferred.
|
|
433
|
+
expect(seekableProp).toHaveBeenCalledWith('seekable');
|
|
434
|
+
|
|
435
|
+
await unmount();
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('leaves seekable false when mpv reports it false', async () => {
|
|
439
|
+
seekableProp.mockImplementation((name: string) =>
|
|
440
|
+
name === 'seekable' ? 'false' : 'null',
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
const { result, unmount } = await renderHook(() => usePlayerProgress(), {
|
|
444
|
+
wrapper,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
expect(result.current.seekable).toBe(false);
|
|
448
|
+
|
|
449
|
+
await unmount();
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('does not coerce an unreadable property into a value', async () => {
|
|
453
|
+
// `getProperty` returns "" on the NOOP bridge and "null" from the
|
|
454
|
+
// native side for an unavailable property. Neither is a boolean,
|
|
455
|
+
// and silently mapping them to false would be a guess - the same
|
|
456
|
+
// class of defect as inventing a title. They must simply be
|
|
457
|
+
// ignored, leaving DEFAULT_PROGRESS in place.
|
|
458
|
+
seekableProp.mockReturnValue('null');
|
|
459
|
+
|
|
460
|
+
const { result, unmount } = await renderHook(() => usePlayerProgress(), {
|
|
461
|
+
wrapper,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
expect(result.current.seekable).toBe(false);
|
|
465
|
+
expect(result.current.cacheRanges).toEqual([]);
|
|
466
|
+
|
|
467
|
+
await unmount();
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('survives a bridge whose getProperty throws', async () => {
|
|
471
|
+
// Hydration is best-effort everywhere else in this effect, so the
|
|
472
|
+
// seed must not be the one call that takes the provider down.
|
|
473
|
+
seekableProp.mockImplementation(() => {
|
|
474
|
+
throw new Error('no mpv instance yet');
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
const { result, unmount } = await renderHook(() => usePlayerProgress(), {
|
|
478
|
+
wrapper,
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
expect(result.current).toBeDefined();
|
|
482
|
+
expect(result.current.seekable).toBe(false);
|
|
483
|
+
|
|
484
|
+
await unmount();
|
|
485
|
+
});
|
|
486
|
+
});
|
|
@@ -173,7 +173,6 @@ describe('usePlayer (no provider)', () => {
|
|
|
173
173
|
expect(typeof c.playlistRemove).toBe('function');
|
|
174
174
|
expect(typeof c.shuffle).toBe('function');
|
|
175
175
|
expect(typeof c.clear).toBe('function');
|
|
176
|
-
expect(typeof c.selectTrack).toBe('function');
|
|
177
176
|
expect(typeof c.cycleTrack).toBe('function');
|
|
178
177
|
expect(typeof c.setTrack).toBe('function');
|
|
179
178
|
expect(typeof c.enterPip).toBe('function');
|
package/src/types/player.ts
CHANGED
|
@@ -199,11 +199,17 @@ export interface PlayerCommands {
|
|
|
199
199
|
clear(): void;
|
|
200
200
|
|
|
201
201
|
// Tracks
|
|
202
|
-
/** Select a track by ID. */
|
|
203
|
-
selectTrack(trackId: number): void;
|
|
204
202
|
/** Cycle to the next/previous track of the given type. */
|
|
205
203
|
cycleTrack(type: 'video' | 'audio' | 'sub'): void;
|
|
206
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Set the active track for a type (trackId < 0 means "no track").
|
|
206
|
+
*
|
|
207
|
+
* `selectTrack(trackId)` was REMOVED. It carried no track type, and its
|
|
208
|
+
* native implementation hardcoded mpv's "vid" property, so selecting a
|
|
209
|
+
* subtitle retargeted the VIDEO track. Use `setTrack(type, trackId)`
|
|
210
|
+
* instead — it maps video/audio/sub to vid/aid/sid and handles disabling
|
|
211
|
+
* via a negative id.
|
|
212
|
+
*/
|
|
207
213
|
setTrack(type: 'video' | 'audio' | 'sub', trackId: number): void;
|
|
208
214
|
|
|
209
215
|
// PiP
|
|
@@ -567,10 +573,6 @@ function buildCommands(): PlayerCommands {
|
|
|
567
573
|
getMpvPlayerModule().playlistClear();
|
|
568
574
|
},
|
|
569
575
|
|
|
570
|
-
selectTrack: (trackId: number) => {
|
|
571
|
-
dlog('commands.selectTrack(', trackId, ')');
|
|
572
|
-
getMpvPlayerModule().selectTrack(trackId);
|
|
573
|
-
},
|
|
574
576
|
cycleTrack: (type: 'video' | 'audio' | 'sub') => {
|
|
575
577
|
dlog('commands.cycleTrack(', type, ')');
|
|
576
578
|
getMpvPlayerModule().cycleTrack(type);
|