@simba-dev/react-native-media-player 3.0.3 → 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/package.json +2 -1
- package/src/bridge/MpvPlayerModule.ts +15 -6
- package/src/components/PlayerProvider.tsx +10 -38
- package/src/index.ts +6 -7
- package/src/types/player.ts +12 -6
- package/tsconfig.json +1 -2
package/README.md
CHANGED
|
@@ -198,7 +198,15 @@ import {SimbaVideo} from '@simba-dev/react-native-media-player';
|
|
|
198
198
|
<SimbaVideo style={{flex: 1}} resizeMode="contain" />;
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
`resizeMode` is `'contain' | 'cover' | 'stretch'` and defaults to `'contain'`.
|
|
201
|
+
`resizeMode` is `'contain' | 'cover' | 'stretch'` and defaults to `'contain'`. Each mode is a
|
|
202
|
+
combination of mpv's own properties, and the difference between them is what the picture does
|
|
203
|
+
inside the view:
|
|
204
|
+
|
|
205
|
+
| `resizeMode` | `video-zoom` | `keepaspect` | `panscan` | What it does |
|
|
206
|
+
| --- | --- | --- | --- | --- |
|
|
207
|
+
| `contain` (default) | `"0"` | `"yes"` | `"0"` | Fits **inside** the view — letterboxed / pillarboxed, aspect kept. |
|
|
208
|
+
| `cover` | `"0"` | `"yes"` | `"1.0"` | **Fills** the view — the overflow is cropped away, aspect kept. |
|
|
209
|
+
| `stretch` | `"0"` | `"no"` | `"0"` | **Fills** the view — aspect ignored. |
|
|
202
210
|
|
|
203
211
|
### Drive it
|
|
204
212
|
|
|
@@ -227,6 +235,10 @@ function Controls() {
|
|
|
227
235
|
directly (`positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `cacheRanges`,
|
|
228
236
|
`cacheFill`).
|
|
229
237
|
|
|
238
|
+
The buffered ranges are quantised onto the grid the scrub bar is drawn at — the timeline is cut
|
|
239
|
+
into `durationMs / 1000` cells and every boundary is snapped to the nearest cell — so the progress
|
|
240
|
+
context no longer changes on every native cache tick.
|
|
241
|
+
|
|
230
242
|
### Optional adapter: resume positions
|
|
231
243
|
|
|
232
244
|
```tsx
|
|
@@ -243,29 +255,46 @@ position in milliseconds, or `undefined` when there is none.
|
|
|
243
255
|
**The library draws no controls.** That has been the contract since 2.0.0.
|
|
244
256
|
|
|
245
257
|
`<DefaultControls>` — the default control bundle the package used to ship — was **removed in
|
|
246
|
-
2.0.0**. The export no longer exists
|
|
247
|
-
|
|
248
|
-
them.
|
|
258
|
+
2.0.0**. The export no longer exists. If you were using it, keep your own copy in your app or
|
|
259
|
+
render your own controls; the library will not supply them.
|
|
249
260
|
|
|
250
261
|
There are two ways to have chrome, and you can mix them:
|
|
251
262
|
|
|
252
263
|
1. **Render your own component** wherever you want it, reading `usePlayer()`,
|
|
253
264
|
`usePlayerProgress()` and `useTheme()`. Nothing else is needed.
|
|
254
265
|
2. **Use the `renderControls` slot** on `<PlayerProvider>`. The function returns the tree to draw
|
|
255
|
-
over the picture
|
|
266
|
+
over the picture. The library draws no overlay for you — you place the controls yourself, in an
|
|
267
|
+
absolutely positioned `View` over the picture:
|
|
256
268
|
|
|
257
269
|
```tsx
|
|
270
|
+
import {StyleSheet, View} from 'react-native';
|
|
271
|
+
import {PlayerProvider, SimbaVideo} from '@simba-dev/react-native-media-player';
|
|
272
|
+
|
|
258
273
|
<PlayerProvider config={config} renderControls={() => <MyControls />}>
|
|
259
|
-
<
|
|
274
|
+
<View style={{flex: 1}}>
|
|
275
|
+
<SimbaVideo style={{flex: 1}} />
|
|
276
|
+
<View style={StyleSheet.absoluteFill}>
|
|
277
|
+
<PlayerChrome />
|
|
278
|
+
</View>
|
|
279
|
+
</View>
|
|
260
280
|
</PlayerProvider>
|
|
261
281
|
```
|
|
262
282
|
|
|
263
283
|
`renderControls` takes no arguments — read what you need from the hooks inside your component.
|
|
264
284
|
The slot is JS-only: it is never sent to the native side. `useRenderControls()` returns the slot,
|
|
265
|
-
or `null` when there is none
|
|
285
|
+
or `null` when there is none — your own component calls it:
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
import {useRenderControls} from '@simba-dev/react-native-media-player';
|
|
289
|
+
|
|
290
|
+
function PlayerChrome() {
|
|
291
|
+
const renderControls = useRenderControls();
|
|
292
|
+
return renderControls != null ? renderControls() : null;
|
|
293
|
+
}
|
|
294
|
+
```
|
|
266
295
|
|
|
267
|
-
`<PlayerRoot>`
|
|
268
|
-
|
|
296
|
+
The picture is `<SimbaVideo />`. `<PlayerRoot>` and `<PlayerSurface>` were **removed in 3.0.0** —
|
|
297
|
+
there is no library-owned overlay; the absolutely positioned `View` above is yours.
|
|
269
298
|
|
|
270
299
|
## Configuration
|
|
271
300
|
|
|
@@ -354,9 +383,7 @@ const theme = useTheme();
|
|
|
354
383
|
| --- | --- | --- |
|
|
355
384
|
| `<SimbaPlayer>` | `config?`, `resumePolicy?`, `children` | The one-import integration point. Composes `PlayerProvider` + `PlayerResumeProvider`. `resumePolicy: (itemId: string) => number \| undefined`. |
|
|
356
385
|
| `<PlayerProvider>` | `config?`, `renderControls?`, `children` | Resolved config, live player state, and the controls slot. |
|
|
357
|
-
| `<PlayerRoot>` | `launchParams?` | The surface placeholder plus the controls overlay. `launchParams` is a `{uri, title, type, startPositionMs, requestId?}` payload; it is loaded once per `(uri, startPositionMs)` pair. |
|
|
358
386
|
| `<SimbaVideo>` | `resizeMode?` + standard view props | The picture. `resizeMode`: `'contain' \| 'cover' \| 'stretch'`, default `'contain'`. |
|
|
359
|
-
| `<PlayerSurface>` | `backgroundColor?` | A transparent `flex: 1` layout placeholder. Not the video surface. |
|
|
360
387
|
|
|
361
388
|
### Hooks
|
|
362
389
|
|
|
@@ -372,7 +399,7 @@ const theme = useTheme();
|
|
|
372
399
|
| `usePlayItem()` | `({id, uri, title}, {type}) => Promise<boolean>` |
|
|
373
400
|
| `useOpenFromUrl()` | `(uri: string) => Promise<boolean>` — accepts `content://` and `file://` URIs, derives a title, classifies the type and opens it. |
|
|
374
401
|
| `useOpenPlaylist()` | `{openPlaylist(entries, opts?)}` → `Promise<boolean>` |
|
|
375
|
-
| `useLaunchPlayback()` | `(launchParams)` — loads a payload once per `(uri, startPositionMs)`
|
|
402
|
+
| `useLaunchPlayback()` | `(launchParams)` — loads a payload once per `(requestId, uri, startPositionMs)` triple. The `requestId` is part of the key, so re-launching the same file at the same position with a new `requestId` loads again. |
|
|
376
403
|
| `useQueue()` / `useQueueLength()` / `useQueueItems()` / `useQueueItemsAs()` | The queue store and convenience selectors. |
|
|
377
404
|
| `usePlaybackHistory()` / `usePlaybackHistoryAs()` | The playback history. |
|
|
378
405
|
| `useQueueSelection()` / `useQueueSelectedIndices()` | The selection store. |
|
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
|
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
|
*
|
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
|