@simba-dev/react-native-media-player 3.0.2 → 3.0.4
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/CHANGELOG.md +2301 -0
- package/README.md +39 -12
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +12 -9
- package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +58 -33
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +12 -26
- package/android/src/main/java/com/simba/player/mpv/PipSourceRect.kt +30 -55
- package/android/src/main/java/com/simba/player/mpv/ResizeMode.kt +180 -0
- package/package.json +2 -1
- package/src/bridge/MpvPlayerModule.ts +15 -6
- package/src/components/PlayerProvider.tsx +10 -38
- package/src/components/SimbaVideo.tsx +12 -29
- package/src/index.ts +6 -7
- package/src/specs/SimbaVideoViewNativeComponent.ts +5 -2
- package/src/types/player.ts +12 -6
- package/tsconfig.json +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
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",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"!android/src/test/",
|
|
24
24
|
"!android/src/main/jniLibs/",
|
|
25
25
|
"assets/",
|
|
26
|
+
"CHANGELOG.md",
|
|
26
27
|
"LICENSE",
|
|
27
28
|
"README.md",
|
|
28
29
|
"react-native.config.js",
|
|
@@ -94,9 +94,11 @@ export interface LaunchParams {
|
|
|
94
94
|
* every in-window caller needs it.
|
|
95
95
|
*
|
|
96
96
|
* `uri` + `startPositionMs` is not a unique identity for a launch, and
|
|
97
|
-
* `useLaunchPlayback` keys its load effect on
|
|
98
|
-
*
|
|
99
|
-
*
|
|
97
|
+
* `useLaunchPlayback` keys its load effect on the whole
|
|
98
|
+
* `requestId | uri | startPositionMs` triple — the `requestId` is part
|
|
99
|
+
* of the key, not decoration. When every launch started a fresh
|
|
100
|
+
* `PlayerActivity`, a key without it was sound — a new React root, so
|
|
101
|
+
* the hook mounted fresh and always fired.
|
|
100
102
|
*
|
|
101
103
|
* That world is gone. Playback now loads into an already-open window, so
|
|
102
104
|
* the hook stays mounted across launches and the same key means the
|
|
@@ -110,7 +112,7 @@ export interface LaunchParams {
|
|
|
110
112
|
readonly requestId?: string;
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
/** All
|
|
115
|
+
/** All 26 events emitted by the Kotlin bridge. */
|
|
114
116
|
export type PlayerEventName =
|
|
115
117
|
| 'onFileLoaded'
|
|
116
118
|
| 'onLoadRequested'
|
|
@@ -1051,8 +1053,15 @@ export function removeAllListeners(event?: PlayerEventName): void {
|
|
|
1051
1053
|
}
|
|
1052
1054
|
}
|
|
1053
1055
|
|
|
1054
|
-
/**
|
|
1055
|
-
|
|
1056
|
+
/**
|
|
1057
|
+
* All 26 player event names — the ONE owner of this list.
|
|
1058
|
+
*
|
|
1059
|
+
* `<PlayerProvider>` imports it to subscribe to every event on mount,
|
|
1060
|
+
* `removeAllListeners()` iterates it when no event is named, and the
|
|
1061
|
+
* test suite derives its expectation from it. A second hand-written
|
|
1062
|
+
* copy of this list is how the count drifted in the first place.
|
|
1063
|
+
*/
|
|
1064
|
+
export const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
1056
1065
|
'onFileLoaded',
|
|
1057
1066
|
'onLoadRequested',
|
|
1058
1067
|
'onPlaybackStateChanged',
|
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
PlayerStateContext,
|
|
25
25
|
} from '../types/player';
|
|
26
26
|
import {
|
|
27
|
+
ALL_PLAYER_EVENTS,
|
|
27
28
|
getMpvPlayerModule,
|
|
28
|
-
PlayerEventName,
|
|
29
29
|
PlayerEventPayloads,
|
|
30
30
|
removeAllListeners,
|
|
31
31
|
subscribePlayerEvent,
|
|
@@ -185,42 +185,14 @@ function PlayerStateProvider({
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
188
|
+
* The event names are NOT declared here. `ALL_PLAYER_EVENTS` is
|
|
189
|
+
* imported from `../bridge/MpvPlayerModule` (see the import above),
|
|
190
|
+
* where it is the single owner of the list. This module used to keep
|
|
191
|
+
* its own copy of the list — a second owner for the same fact — while
|
|
192
|
+
* the test suite kept a third, hand-written one that had already
|
|
193
|
+
* dropped `onLoadRequested` (the test now derives its expectation from
|
|
194
|
+
* the bridge's list instead).
|
|
195
195
|
*/
|
|
196
|
-
const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
197
|
-
'onFileLoaded',
|
|
198
|
-
'onLoadRequested',
|
|
199
|
-
'onPlaybackStateChanged',
|
|
200
|
-
'onPositionChanged',
|
|
201
|
-
'onDurationChanged',
|
|
202
|
-
'onPropertyChanged',
|
|
203
|
-
'onTracksChanged',
|
|
204
|
-
'onChapterChanged',
|
|
205
|
-
'onVideoParamsChanged',
|
|
206
|
-
'onError',
|
|
207
|
-
'onBuffering',
|
|
208
|
-
'onCacheFill',
|
|
209
|
-
'onCacheState',
|
|
210
|
-
'onSeekable',
|
|
211
|
-
'onSeeking',
|
|
212
|
-
'onEndFile',
|
|
213
|
-
'onPlaybackRestart',
|
|
214
|
-
'onEndReached',
|
|
215
|
-
'onAudioDeviceChanged',
|
|
216
|
-
'onVolumeChanged',
|
|
217
|
-
'onSpeedChanged',
|
|
218
|
-
'videoReconfig',
|
|
219
|
-
'onPipModeChanged',
|
|
220
|
-
'onPipPlayPause',
|
|
221
|
-
'onPipExpand',
|
|
222
|
-
'onPipClose',
|
|
223
|
-
];
|
|
224
196
|
|
|
225
197
|
/**
|
|
226
198
|
* mpv properties the provider observes, and the JS event each one backs
|
|
@@ -488,7 +460,7 @@ export interface PlayerProviderProps {
|
|
|
488
460
|
* - **Initial hydration** (mount): synchronous bridge getters fill in
|
|
489
461
|
* position / duration / playback state / volume / mute / speed /
|
|
490
462
|
* loop / playlist / tracks / chapters / video params.
|
|
491
|
-
* - **Event subscriptions** (mount): all
|
|
463
|
+
* - **Event subscriptions** (mount): all 26 mpv events are subscribed
|
|
492
464
|
* via `subscribePlayerEvent` and dispatched to `applyPlayerEvent`.
|
|
493
465
|
* - **Mount-time level seeds** (mount): `seekable` and `mute` are read once
|
|
494
466
|
* via the sync `getProperty` getter, because mpv emits those two as
|
|
@@ -629,7 +601,7 @@ export function PlayerProvider({
|
|
|
629
601
|
console.warn('[simba-player] hydratePlayerState failed:', e);
|
|
630
602
|
}
|
|
631
603
|
|
|
632
|
-
// ── 2. Subscribe to all
|
|
604
|
+
// ── 2. Subscribe to all 26 mpv events ───────────────────────────────
|
|
633
605
|
// Each event handler reads the current state + progress from the
|
|
634
606
|
// refs, applies the patch via the pure `applyPlayerEvent`
|
|
635
607
|
// reducer, writes back to the refs, and schedules a re-render
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { StyleSheet } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { getMpvPlayerModule } from '../bridge/MpvPlayerModule';
|
|
@@ -9,23 +9,18 @@ export type SimbaVideoResizeMode = 'contain' | 'cover' | 'stretch';
|
|
|
9
9
|
|
|
10
10
|
export interface SimbaVideoProps extends NativeSimbaVideoViewProps {
|
|
11
11
|
/**
|
|
12
|
-
* How the picture fills this view.
|
|
13
|
-
* (0 / 1 / 2) rather than being reimplemented.
|
|
12
|
+
* How the picture fills this view.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
14
|
+
* - `contain` - fit inside the view, letterboxed / pillarboxed.
|
|
15
|
+
* - `cover` - fill the view, cropping the overflow, aspect preserved.
|
|
16
|
+
* - `stretch` - fill the view, aspect ignored.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* `contain` is correct: `0` is unscaled, so the picture keeps its aspect
|
|
24
|
-
* and is letterboxed into the view.
|
|
25
|
-
*
|
|
26
|
-
* The fix is mpv's `panscan` (`1.0` for cover) and `keepaspect` (`no` for
|
|
27
|
-
* stretch), which is a change in the native half. Until that lands, treat
|
|
28
|
-
* `cover` and `stretch` as "a magnified fit", not as a cover and a stretch.
|
|
18
|
+
* The MODE NAME crosses into the native side, which owns the mapping to
|
|
19
|
+
* mpv's own properties (`video-zoom` + `keepaspect` + `panscan`). Nothing
|
|
20
|
+
* is translated here: mpv's `video-zoom` is a log2 **scale factor** (`0` is
|
|
21
|
+
* unscaled, `1` is twice the size, `2` is four times the size), so sending
|
|
22
|
+
* it a zoom for "cover" would magnify the picture instead of filling the
|
|
23
|
+
* view.
|
|
29
24
|
*
|
|
30
25
|
* @default 'contain'
|
|
31
26
|
*/
|
|
@@ -101,18 +96,6 @@ export function SimbaVideo(props: SimbaVideoProps): React.ReactElement {
|
|
|
101
96
|
*/
|
|
102
97
|
const resolvedPtr = nativePtr ?? getMpvPlayerModule().getNativePtr();
|
|
103
98
|
|
|
104
|
-
const videoZoom = useMemo(() => {
|
|
105
|
-
switch (resizeMode) {
|
|
106
|
-
case 'cover':
|
|
107
|
-
return '1';
|
|
108
|
-
case 'stretch':
|
|
109
|
-
return '2';
|
|
110
|
-
case 'contain':
|
|
111
|
-
default:
|
|
112
|
-
return '0';
|
|
113
|
-
}
|
|
114
|
-
}, [resizeMode]);
|
|
115
|
-
|
|
116
99
|
return (
|
|
117
100
|
<NativeSimbaVideoView
|
|
118
101
|
{...rest}
|
|
@@ -120,7 +103,7 @@ export function SimbaVideo(props: SimbaVideoProps): React.ReactElement {
|
|
|
120
103
|
paused={paused ?? false}
|
|
121
104
|
muted={muted ?? false}
|
|
122
105
|
volume={volume ?? 100}
|
|
123
|
-
resizeMode={
|
|
106
|
+
resizeMode={resizeMode}
|
|
124
107
|
style={[styles.fill, style]}
|
|
125
108
|
/>
|
|
126
109
|
);
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @simba/react-native-media-player — public API surface.
|
|
2
|
+
* @simba-dev/react-native-media-player — public API surface.
|
|
3
3
|
*
|
|
4
4
|
* The surface is three things:
|
|
5
5
|
*
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
* - `usePlayerProgress()` — position, duration and the buffer /
|
|
11
11
|
* cache fields, split out from `usePlayer()` so a scrubber does
|
|
12
12
|
* not re-render on every volume or track change. The values come
|
|
13
|
-
* from the native mpv event stream
|
|
14
|
-
*
|
|
15
|
-
* no JS-side timer polling the
|
|
13
|
+
* from the native mpv event stream — position at 4 Hz, because the
|
|
14
|
+
* native side coalesces `time-pos` at 250 ms — plus a one-shot
|
|
15
|
+
* hydration read at mount; there is no JS-side timer polling the
|
|
16
|
+
* bridge.
|
|
16
17
|
* - `<SimbaVideo>` — the video picture. It is an ordinary view in
|
|
17
18
|
* the consumer's own React tree, so React Native owns the
|
|
18
19
|
* layout, the z-order and the lifecycle. Playback and
|
|
@@ -37,9 +38,7 @@
|
|
|
37
38
|
*
|
|
38
39
|
* The contract now says what it means: **the library draws no chrome.**
|
|
39
40
|
* A consumer that wants controls renders them, through the
|
|
40
|
-
* `renderControls` slot on `<PlayerProvider>`.
|
|
41
|
-
* the surface and the consumer's controls, and **nothing else** when
|
|
42
|
-
* `renderControls` is absent.
|
|
41
|
+
* `renderControls` slot on `<PlayerProvider>`.
|
|
43
42
|
*
|
|
44
43
|
* This is a **breaking** change, hence the major version.
|
|
45
44
|
*
|
|
@@ -75,8 +75,11 @@ export interface NativeProps extends ViewProps {
|
|
|
75
75
|
* - `cover` - fill the view, cropping the overflow, aspect preserved.
|
|
76
76
|
* - `stretch` - fill the view, aspect ignored.
|
|
77
77
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
78
|
+
* The MODE NAME crosses into the native side, which owns the mapping onto
|
|
79
|
+
* mpv's own properties (`video-zoom` + `keepaspect` + `panscan`). mpv's
|
|
80
|
+
* `video-zoom` is a log2 **scale factor** (`0` unscaled, `1` twice the
|
|
81
|
+
* size, `2` four times the size), so it is not a fit / fill / stretch enum
|
|
82
|
+
* and is never sent one.
|
|
80
83
|
*/
|
|
81
84
|
resizeMode?: WithDefault<string, 'contain'>;
|
|
82
85
|
}
|
package/src/types/player.ts
CHANGED
|
@@ -141,11 +141,12 @@ export interface PlaylistEntry {
|
|
|
141
141
|
* `usePlayerProgress()` is separate from `usePlayer()` so consumers
|
|
142
142
|
* that only need position/duration don't re-render on every
|
|
143
143
|
* `onPropertyChanged('volume')` etc. The provider updates the
|
|
144
|
-
* progress context from the native mpv event stream — position
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
144
|
+
* progress context from the native mpv event stream — position arrives
|
|
145
|
+
* on the `time-pos` property event, coalesced natively at 250 ms (4 Hz),
|
|
146
|
+
* while duration arrives on the `duration` property event, which is NOT
|
|
147
|
+
* coalesced and is forwarded as it arrives — and `isBuffering` /
|
|
148
|
+
* `isSeeking` / `seekable` / `cacheRanges` / `cacheFill` each have their
|
|
149
|
+
* own dedicated event — plus a one-shot hydration read at mount.
|
|
149
150
|
*/
|
|
150
151
|
export interface PlayerProgress {
|
|
151
152
|
// ── V12 surface (preserved) ───────────────────────────────────────────
|
|
@@ -169,6 +170,11 @@ export interface PlayerProgress {
|
|
|
169
170
|
* native bridge converts, because it is the only layer that knows which
|
|
170
171
|
* unit a payload carried.
|
|
171
172
|
*
|
|
173
|
+
* The published boundaries are SNAPPED to the grid the scrub bar is
|
|
174
|
+
* drawn at — the timeline cut into `durationMs / 1000` cells, or a fixed
|
|
175
|
+
* one-second grid when the duration is unknown — so the values are a
|
|
176
|
+
* rounded grid, not raw mpv readings.
|
|
177
|
+
*
|
|
172
178
|
* Empty when the source exposes no time-space cache information. A byte
|
|
173
179
|
* offset is NOT a time and is never reported here: a range painted from
|
|
174
180
|
* byte offsets would claim that unbuffered data is buffered.
|
|
@@ -919,7 +925,7 @@ export function usePlayer(): UsePlayerResult {
|
|
|
919
925
|
* volume / track / chapter change.
|
|
920
926
|
*
|
|
921
927
|
* The provider updates the progress context only on:
|
|
922
|
-
* - the native mpv event stream (position, duration,
|
|
928
|
+
* - the native mpv event stream (position, duration, …)
|
|
923
929
|
* - `onBuffering` / `onSeeking` / `onSeekable` / `onCacheState` /
|
|
924
930
|
* `onCacheFill` events
|
|
925
931
|
* - a one-shot hydration read at mount
|