@simba-dev/react-native-media-player 3.0.3 → 3.0.5
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 +2351 -0
- package/README.md +43 -12
- package/android/src/main/java/com/simba/player/PipManager.kt +26 -11
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +99 -94
- package/package.json +2 -1
- package/src/bridge/MpvPlayerModule.ts +38 -7
- package/src/components/PlayerProvider.tsx +10 -38
- package/src/index.ts +6 -7
- package/src/types/config.ts +12 -1
- package/src/types/player.ts +13 -6
- package/tsconfig.json +1 -2
package/README.md
CHANGED
|
@@ -139,6 +139,10 @@ Your launcher Activity has to opt in:
|
|
|
139
139
|
`resizeableActivity="true"` is not optional. An Activity that is not resizeable cannot enter
|
|
140
140
|
Picture-in-Picture.
|
|
141
141
|
|
|
142
|
+
If `config.pip.autoEnterOnLeave` is on, the Activity also has to forward the platform’s leave
|
|
143
|
+
hint to the library — see [Picture-in-Picture](#picture-in-picture) for the two lines of Kotlin
|
|
144
|
+
and the JS that goes with them.
|
|
145
|
+
|
|
142
146
|
### Background audio
|
|
143
147
|
|
|
144
148
|
```xml
|
|
@@ -198,7 +202,15 @@ import {SimbaVideo} from '@simba-dev/react-native-media-player';
|
|
|
198
202
|
<SimbaVideo style={{flex: 1}} resizeMode="contain" />;
|
|
199
203
|
```
|
|
200
204
|
|
|
201
|
-
`resizeMode` is `'contain' | 'cover' | 'stretch'` and defaults to `'contain'`.
|
|
205
|
+
`resizeMode` is `'contain' | 'cover' | 'stretch'` and defaults to `'contain'`. Each mode is a
|
|
206
|
+
combination of mpv's own properties, and the difference between them is what the picture does
|
|
207
|
+
inside the view:
|
|
208
|
+
|
|
209
|
+
| `resizeMode` | `video-zoom` | `keepaspect` | `panscan` | What it does |
|
|
210
|
+
| --- | --- | --- | --- | --- |
|
|
211
|
+
| `contain` (default) | `"0"` | `"yes"` | `"0"` | Fits **inside** the view — letterboxed / pillarboxed, aspect kept. |
|
|
212
|
+
| `cover` | `"0"` | `"yes"` | `"1.0"` | **Fills** the view — the overflow is cropped away, aspect kept. |
|
|
213
|
+
| `stretch` | `"0"` | `"no"` | `"0"` | **Fills** the view — aspect ignored. |
|
|
202
214
|
|
|
203
215
|
### Drive it
|
|
204
216
|
|
|
@@ -227,6 +239,10 @@ function Controls() {
|
|
|
227
239
|
directly (`positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `cacheRanges`,
|
|
228
240
|
`cacheFill`).
|
|
229
241
|
|
|
242
|
+
The buffered ranges are quantised onto the grid the scrub bar is drawn at — the timeline is cut
|
|
243
|
+
into `durationMs / 1000` cells and every boundary is snapped to the nearest cell — so the progress
|
|
244
|
+
context no longer changes on every native cache tick.
|
|
245
|
+
|
|
230
246
|
### Optional adapter: resume positions
|
|
231
247
|
|
|
232
248
|
```tsx
|
|
@@ -243,29 +259,46 @@ position in milliseconds, or `undefined` when there is none.
|
|
|
243
259
|
**The library draws no controls.** That has been the contract since 2.0.0.
|
|
244
260
|
|
|
245
261
|
`<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.
|
|
262
|
+
2.0.0**. The export no longer exists. If you were using it, keep your own copy in your app or
|
|
263
|
+
render your own controls; the library will not supply them.
|
|
249
264
|
|
|
250
265
|
There are two ways to have chrome, and you can mix them:
|
|
251
266
|
|
|
252
267
|
1. **Render your own component** wherever you want it, reading `usePlayer()`,
|
|
253
268
|
`usePlayerProgress()` and `useTheme()`. Nothing else is needed.
|
|
254
269
|
2. **Use the `renderControls` slot** on `<PlayerProvider>`. The function returns the tree to draw
|
|
255
|
-
over the picture
|
|
270
|
+
over the picture. The library draws no overlay for you — you place the controls yourself, in an
|
|
271
|
+
absolutely positioned `View` over the picture:
|
|
256
272
|
|
|
257
273
|
```tsx
|
|
274
|
+
import {StyleSheet, View} from 'react-native';
|
|
275
|
+
import {PlayerProvider, SimbaVideo} from '@simba-dev/react-native-media-player';
|
|
276
|
+
|
|
258
277
|
<PlayerProvider config={config} renderControls={() => <MyControls />}>
|
|
259
|
-
<
|
|
278
|
+
<View style={{flex: 1}}>
|
|
279
|
+
<SimbaVideo style={{flex: 1}} />
|
|
280
|
+
<View style={StyleSheet.absoluteFill}>
|
|
281
|
+
<PlayerChrome />
|
|
282
|
+
</View>
|
|
283
|
+
</View>
|
|
260
284
|
</PlayerProvider>
|
|
261
285
|
```
|
|
262
286
|
|
|
263
287
|
`renderControls` takes no arguments — read what you need from the hooks inside your component.
|
|
264
288
|
The slot is JS-only: it is never sent to the native side. `useRenderControls()` returns the slot,
|
|
265
|
-
or `null` when there is none
|
|
289
|
+
or `null` when there is none — your own component calls it:
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
import {useRenderControls} from '@simba-dev/react-native-media-player';
|
|
293
|
+
|
|
294
|
+
function PlayerChrome() {
|
|
295
|
+
const renderControls = useRenderControls();
|
|
296
|
+
return renderControls != null ? renderControls() : null;
|
|
297
|
+
}
|
|
298
|
+
```
|
|
266
299
|
|
|
267
|
-
`<PlayerRoot>`
|
|
268
|
-
|
|
300
|
+
The picture is `<SimbaVideo />`. `<PlayerRoot>` and `<PlayerSurface>` were **removed in 3.0.0** —
|
|
301
|
+
there is no library-owned overlay; the absolutely positioned `View` above is yours.
|
|
269
302
|
|
|
270
303
|
## Configuration
|
|
271
304
|
|
|
@@ -354,9 +387,7 @@ const theme = useTheme();
|
|
|
354
387
|
| --- | --- | --- |
|
|
355
388
|
| `<SimbaPlayer>` | `config?`, `resumePolicy?`, `children` | The one-import integration point. Composes `PlayerProvider` + `PlayerResumeProvider`. `resumePolicy: (itemId: string) => number \| undefined`. |
|
|
356
389
|
| `<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
390
|
| `<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
391
|
|
|
361
392
|
### Hooks
|
|
362
393
|
|
|
@@ -372,7 +403,7 @@ const theme = useTheme();
|
|
|
372
403
|
| `usePlayItem()` | `({id, uri, title}, {type}) => Promise<boolean>` |
|
|
373
404
|
| `useOpenFromUrl()` | `(uri: string) => Promise<boolean>` — accepts `content://` and `file://` URIs, derives a title, classifies the type and opens it. |
|
|
374
405
|
| `useOpenPlaylist()` | `{openPlaylist(entries, opts?)}` → `Promise<boolean>` |
|
|
375
|
-
| `useLaunchPlayback()` | `(launchParams)` — loads a payload once per `(uri, startPositionMs)`
|
|
406
|
+
| `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
407
|
| `useQueue()` / `useQueueLength()` / `useQueueItems()` / `useQueueItemsAs()` | The queue store and convenience selectors. |
|
|
377
408
|
| `usePlaybackHistory()` / `usePlaybackHistoryAs()` | The playback history. |
|
|
378
409
|
| `useQueueSelection()` / `useQueueSelectedIndices()` | The selection store. |
|
|
@@ -68,7 +68,6 @@ object PipManager {
|
|
|
68
68
|
sourceRectHint: Rect? = null,
|
|
69
69
|
chapterTitle: String? = null,
|
|
70
70
|
progressPercentage: String? = null,
|
|
71
|
-
autoEnter: Boolean = false,
|
|
72
71
|
): PictureInPictureParams {
|
|
73
72
|
val actions = mutableListOf<RemoteAction>()
|
|
74
73
|
|
|
@@ -133,17 +132,33 @@ object PipManager {
|
|
|
133
132
|
builder.setSeamlessResizeEnabled(true)
|
|
134
133
|
}
|
|
135
134
|
|
|
136
|
-
//
|
|
135
|
+
// NO `setAutoEnterEnabled` HERE, and that is deliberate.
|
|
137
136
|
//
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
// The platform's auto-enter switch makes the SYSTEM transition the
|
|
138
|
+
// activity into PiP when the user leaves the app, without the app
|
|
139
|
+
// being able to do anything first. That is the wrong order for a
|
|
140
|
+
// consumer that draws its own chrome over the picture: an Activity
|
|
141
|
+
// in PiP does not redraw, so whatever the window held at the
|
|
142
|
+
// moment of the transition is what the PiP window keeps showing -
|
|
143
|
+
// frozen, dead and scaled down.
|
|
144
|
+
//
|
|
145
|
+
// Measured on device on 2026-11-03: the consumer's full expanded
|
|
146
|
+
// chrome (header band, scrub row, +-10 buttons, the big pause
|
|
147
|
+
// button) was painted into the PiP window, its buttons were DEAD
|
|
148
|
+
// (tapping pause did not pause) and its clock was FROZEN at
|
|
149
|
+
// 51:09 while the real position was 54:15 - while the consumer's
|
|
150
|
+
// own state already said `pipActive: true` and `isExpanded:
|
|
151
|
+
// false`.
|
|
152
|
+
//
|
|
153
|
+
// So auto-enter on leave is the CONSUMER's to perform, in the only
|
|
154
|
+
// order that works: remove the chrome, let the frame that drew it
|
|
155
|
+
// go by, and only then ask for the window. The library's part is
|
|
156
|
+
// to tell the consumer WHEN the user is leaving - the
|
|
157
|
+
// `onUserLeaveHint` event - and to keep the params it hands the
|
|
158
|
+
// platform free of the platform's own auto-enter switch.
|
|
159
|
+
//
|
|
160
|
+
// The consumer's Activity overrides `onUserLeaveHint()`, which
|
|
161
|
+
// works on every API level, unlike the platform switch (API 31+).
|
|
147
162
|
|
|
148
163
|
// Source rect hint for smooth entry animation (Android 12+)
|
|
149
164
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && sourceRectHint != null) {
|
|
@@ -129,6 +129,20 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
129
129
|
*/
|
|
130
130
|
private var pipAutoEnter: Boolean = false
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* The same policy, mirrored where the COMPANION can read it.
|
|
134
|
+
*
|
|
135
|
+
* `notifyUserLeaveHint()` is a companion function: it is called
|
|
136
|
+
* from the consumer's Activity, which has no reference to this
|
|
137
|
+
* module instance, so it cannot read the instance field above.
|
|
138
|
+
* The instance writes this mirror when it applies the policy.
|
|
139
|
+
*
|
|
140
|
+
* The same pattern `debugLoggingEnabled` uses.
|
|
141
|
+
*/
|
|
142
|
+
@Volatile
|
|
143
|
+
var pipAutoEnterForCompanion: Boolean = false
|
|
144
|
+
private set
|
|
145
|
+
|
|
132
146
|
/**
|
|
133
147
|
* Phase 21: recursive JSONObject → Kotlin Map converter. Used
|
|
134
148
|
* by [setConfig] so the stored config can be consumed
|
|
@@ -198,6 +212,51 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
198
212
|
Log.w(TAG, "onPictureInPictureModeChanged: emit threw", e)
|
|
199
213
|
}
|
|
200
214
|
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Called from the consumer's `Activity.onUserLeaveHint()` - the
|
|
218
|
+
* user is leaving the app (home, recents, app switcher).
|
|
219
|
+
*
|
|
220
|
+
* The consumer needs this because the PiP ENTRY has to be in the
|
|
221
|
+
* consumer's hands, not the platform's: an Activity in PiP does
|
|
222
|
+
* not redraw, so a consumer that draws its own chrome over the
|
|
223
|
+
* picture has to remove that chrome BEFORE the window is frozen.
|
|
224
|
+
* The platform's own auto-enter switch cannot give it that
|
|
225
|
+
* chance - see `PipManager.buildPipParams` for the measurement.
|
|
226
|
+
*
|
|
227
|
+
* So the library's job is to say WHEN, and the consumer decides
|
|
228
|
+
* whether to act: it removes its chrome, lets the frame that drew
|
|
229
|
+
* it go by, and then asks the OS for the window itself.
|
|
230
|
+
*
|
|
231
|
+
* The auto-enter policy is the consumer's own `pip.autoEnterOnLeave`
|
|
232
|
+
* config, so this is a no-op when the consumer does not want
|
|
233
|
+
* auto-enter.
|
|
234
|
+
*/
|
|
235
|
+
fun notifyUserLeaveHint() {
|
|
236
|
+
Log.i(
|
|
237
|
+
TAG,
|
|
238
|
+
"companion.notifyUserLeaveHint: autoEnter=$pipAutoEnterForCompanion " +
|
|
239
|
+
"instance=${instance != null}",
|
|
240
|
+
)
|
|
241
|
+
if (!pipAutoEnterForCompanion) {
|
|
242
|
+
Log.i(
|
|
243
|
+
TAG,
|
|
244
|
+
"companion.notifyUserLeaveHint: auto-enter is off; not telling the consumer",
|
|
245
|
+
)
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
val ctx = instance ?: run {
|
|
249
|
+
Log.w(TAG, "notifyUserLeaveHint: module instance not initialized yet")
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
254
|
+
.emit("onUserLeaveHint", Arguments.createMap())
|
|
255
|
+
Log.i(TAG, "companion.notifyUserLeaveHint: emit succeeded")
|
|
256
|
+
} catch (e: Exception) {
|
|
257
|
+
Log.w(TAG, "notifyUserLeaveHint: emit threw", e)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
201
260
|
}
|
|
202
261
|
|
|
203
262
|
init {
|
|
@@ -301,13 +360,13 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
301
360
|
"surfaceAttached" -> "onSurfaceAttached"
|
|
302
361
|
else -> event
|
|
303
362
|
}
|
|
304
|
-
// The video's dimensions just changed.
|
|
305
|
-
//
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
363
|
+
// The video's dimensions just changed. Nothing has to be
|
|
364
|
+
// refreshed here any more: the params the platform reads are
|
|
365
|
+
// the ones the CONSUMER's entry carries, and the consumer
|
|
366
|
+
// builds them at the moment it asks for the window - by then
|
|
367
|
+
// it knows the video's current shape. (The platform's own
|
|
368
|
+
// auto-enter switch, which used to read params stashed on the
|
|
369
|
+
// activity, is gone: see `PipManager.buildPipParams`.)
|
|
311
370
|
try {
|
|
312
371
|
val payload = JsonUtil.jsonStringToReactMap(jsonPayload)
|
|
313
372
|
eventEmitter.emit(jsEvent, payload)
|
|
@@ -2294,20 +2353,30 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2294
2353
|
}
|
|
2295
2354
|
|
|
2296
2355
|
/**
|
|
2297
|
-
* Apply `pip.autoEnterOnLeave`
|
|
2298
|
-
*
|
|
2299
|
-
*
|
|
2300
|
-
*
|
|
2301
|
-
*
|
|
2302
|
-
*
|
|
2303
|
-
*
|
|
2304
|
-
*
|
|
2305
|
-
*
|
|
2306
|
-
*
|
|
2307
|
-
*
|
|
2308
|
-
*
|
|
2309
|
-
*
|
|
2310
|
-
*
|
|
2356
|
+
* Apply `pip.autoEnterOnLeave` — remember the policy, and tell the
|
|
2357
|
+
* CONSUMER when the user leaves.
|
|
2358
|
+
*
|
|
2359
|
+
* What this does NOT do any more: arm the platform's own switch
|
|
2360
|
+
* (`PictureInPictureParams.Builder.setAutoEnterEnabled`, API 31+).
|
|
2361
|
+
* The platform's switch makes the SYSTEM transition the activity into
|
|
2362
|
+
* PiP without the consumer being able to do anything first, and an
|
|
2363
|
+
* Activity in PiP does not redraw — so a consumer that draws its own
|
|
2364
|
+
* chrome over the picture had that chrome frozen into the PiP
|
|
2365
|
+
* window, dead and scaled down. Measured on device on 2026-11-03.
|
|
2366
|
+
* See `PipManager.buildPipParams` for the full account.
|
|
2367
|
+
*
|
|
2368
|
+
* What it does now: the policy is remembered (so
|
|
2369
|
+
* `notifyUserLeaveHint()` can decide whether to speak at all), and
|
|
2370
|
+
* when the consumer's Activity reports that the user is leaving, the
|
|
2371
|
+
* consumer is told through the `onUserLeaveHint` event. The consumer
|
|
2372
|
+
* then removes its chrome, lets the frame that drew it go by, and
|
|
2373
|
+
* asks the OS for the window itself.
|
|
2374
|
+
*
|
|
2375
|
+
* The consumer's Activity must override `onUserLeaveHint()` and
|
|
2376
|
+
* declare `android:supportsPictureInPicture="true"`. Both are the
|
|
2377
|
+
* consumer's, not this library's — it ships no Activity (the
|
|
2378
|
+
* one-Activity architecture). `onUserLeaveHint()` works on EVERY API
|
|
2379
|
+
* level, unlike the platform switch, which needed API 31+.
|
|
2311
2380
|
*
|
|
2312
2381
|
* @param config the RESOLVED config map, as parsed by `setConfig`.
|
|
2313
2382
|
*/
|
|
@@ -2315,7 +2384,15 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2315
2384
|
try {
|
|
2316
2385
|
val desired = PipAutoEnterPolicy.desiredAutoEnter(config) ?: return
|
|
2317
2386
|
pipAutoEnter = desired
|
|
2318
|
-
|
|
2387
|
+
// The policy is remembered so `notifyUserLeaveHint()` knows
|
|
2388
|
+
// whether to tell the consumer that it should enter PiP. The
|
|
2389
|
+
// platform's OWN auto-enter switch is NOT armed: the system
|
|
2390
|
+
// would transition the activity without the consumer being
|
|
2391
|
+
// able to remove its chrome first, and an Activity in PiP
|
|
2392
|
+
// does not redraw - so the consumer's chrome would be frozen
|
|
2393
|
+
// into the PiP window as a dead layer. See
|
|
2394
|
+
// `PipManager.buildPipParams` for the measurement.
|
|
2395
|
+
pipAutoEnterForCompanion = desired
|
|
2319
2396
|
} catch (t: Throwable) {
|
|
2320
2397
|
// Never let this reject the `setConfig` promise: the config
|
|
2321
2398
|
// itself was stored fine, and a rejected promise would tell
|
|
@@ -2379,77 +2456,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2379
2456
|
)
|
|
2380
2457
|
}
|
|
2381
2458
|
|
|
2382
|
-
/**
|
|
2383
|
-
* Push the PiP params the SYSTEM will use onto the Activity.
|
|
2384
|
-
*
|
|
2385
|
-
* `Activity.setPictureInPictureParams` is what the platform reads
|
|
2386
|
-
* when it transitions the activity into PiP BY ITSELF - which is
|
|
2387
|
-
* exactly the swipe-home path that `pip.autoEnterOnLeave` asks for.
|
|
2388
|
-
* The params `enterPip` passes to `enterPictureInPictureMode` only
|
|
2389
|
-
* describe a MANUAL entry.
|
|
2390
|
-
*
|
|
2391
|
-
* So the auto-enter flag has to live on the activity's params, and
|
|
2392
|
-
* it has to carry the video's CURRENT aspect ratio - a stale aspect
|
|
2393
|
-
* means the auto-entered window has the shape of the previous video.
|
|
2394
|
-
* That is why this runs again on every `videoReconfig`: that is the
|
|
2395
|
-
* moment mpv reports new dimensions.
|
|
2396
|
-
*
|
|
2397
|
-
* `Activity.setAutoEnterEnabled` does NOT exist - the platform's
|
|
2398
|
-
* switch is `PictureInPictureParams.Builder.setAutoEnterEnabled`,
|
|
2399
|
-
* which is API 31+. Below that the OS cannot auto-enter at all.
|
|
2400
|
-
*/
|
|
2401
|
-
private fun applyActivityPipParams() {
|
|
2402
|
-
try {
|
|
2403
|
-
if (!pipAutoEnter) return
|
|
2404
|
-
val activity = reactApplicationContext.currentActivity
|
|
2405
|
-
if (activity == null) {
|
|
2406
|
-
Log.w(
|
|
2407
|
-
TAG,
|
|
2408
|
-
"[PlaybackTrace][Bridge][pip] no activity yet; auto-enter PiP not applied",
|
|
2409
|
-
)
|
|
2410
|
-
return
|
|
2411
|
-
}
|
|
2412
|
-
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S) {
|
|
2413
|
-
Log.w(
|
|
2414
|
-
TAG,
|
|
2415
|
-
"[PlaybackTrace][Bridge][pip] auto-enter PiP needs Android 12 (API 31)+; " +
|
|
2416
|
-
"below that the OS cannot auto-enter, so PiP entry stays manual",
|
|
2417
|
-
)
|
|
2418
|
-
return
|
|
2419
|
-
}
|
|
2420
|
-
// The window's shape and the source rect hint are taken from the
|
|
2421
|
-
// SAME frame, so they can never disagree. The system scales the
|
|
2422
|
-
// hinted region to the window non-proportionally when the two
|
|
2423
|
-
// shapes differ, and the video visibly arrives stretched.
|
|
2424
|
-
//
|
|
2425
|
-
// The frame's shape follows the picture's mode: with `contain`
|
|
2426
|
-
// (the app's default) the frame inside the view IS the video,
|
|
2427
|
-
// letterboxed into the view's own shape; with `cover` or
|
|
2428
|
-
// `stretch` the picture fills the view, so the frame IS the
|
|
2429
|
-
// view's rect and the window takes the view's shape. Either way
|
|
2430
|
-
// the window's shape does not change here — only the hint does,
|
|
2431
|
-
// from `null` (a black rectangle) to a real rect that points at
|
|
2432
|
-
// the picture.
|
|
2433
|
-
val frame = pipSourceRectInWindow()
|
|
2434
|
-
val aspect = frame?.aspect ?: (currentVideoAspect() ?: (16f / 9f))
|
|
2435
|
-
val params = com.simba.player.PipManager.buildPipParams(
|
|
2436
|
-
context = activity,
|
|
2437
|
-
aspect = aspect,
|
|
2438
|
-
sourceRectHint = frame?.let { Rect(it.left, it.top, it.right, it.bottom) },
|
|
2439
|
-
autoEnter = true,
|
|
2440
|
-
)
|
|
2441
|
-
activity.runOnUiThread {
|
|
2442
|
-
activity.setPictureInPictureParams(params)
|
|
2443
|
-
Log.i(
|
|
2444
|
-
TAG,
|
|
2445
|
-
"[PlaybackTrace][Bridge][pip] activity PiP params set, autoEnter=true",
|
|
2446
|
-
)
|
|
2447
|
-
}
|
|
2448
|
-
} catch (t: Throwable) {
|
|
2449
|
-
Log.w(TAG, "[PlaybackTrace][Bridge][pip] applying activity params failed", t)
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
|
|
2453
2459
|
// ── Picture-in-Picture ─────────────────────────────────────────────────
|
|
2454
2460
|
|
|
2455
2461
|
/**
|
|
@@ -2554,7 +2560,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2554
2560
|
sourceRectHint = sourceRect,
|
|
2555
2561
|
chapterTitle = title,
|
|
2556
2562
|
progressPercentage = pct,
|
|
2557
|
-
autoEnter = pipAutoEnter,
|
|
2558
2563
|
)
|
|
2559
2564
|
// `enterPictureInPictureMode` ANSWERS whether the OS
|
|
2560
2565
|
// accepted the request, and the answer was being
|
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.5",
|
|
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,16 @@ export interface LaunchParams {
|
|
|
110
112
|
readonly requestId?: string;
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* All 27 events emitted by the Kotlin bridge.
|
|
117
|
+
*
|
|
118
|
+
* `onUserLeaveHint` is the 27th: the native side telling the consumer
|
|
119
|
+
* that the user is leaving the app. It exists because a consumer that
|
|
120
|
+
* draws its own chrome over the picture has to be able to remove that
|
|
121
|
+
* chrome BEFORE the Activity enters Picture-in-Picture. See
|
|
122
|
+
* `PipManager`'s note on why the OS-initiated transition cannot be used
|
|
123
|
+
* for that.
|
|
124
|
+
*/
|
|
114
125
|
export type PlayerEventName =
|
|
115
126
|
| 'onFileLoaded'
|
|
116
127
|
| 'onLoadRequested'
|
|
@@ -137,7 +148,8 @@ export type PlayerEventName =
|
|
|
137
148
|
| 'onPipModeChanged'
|
|
138
149
|
| 'onPipPlayPause'
|
|
139
150
|
| 'onPipExpand'
|
|
140
|
-
| 'onPipClose'
|
|
151
|
+
| 'onPipClose'
|
|
152
|
+
| 'onUserLeaveHint';
|
|
141
153
|
|
|
142
154
|
/** Typed payload map for each event. */
|
|
143
155
|
export interface PlayerEventPayloads {
|
|
@@ -196,6 +208,17 @@ export interface PlayerEventPayloads {
|
|
|
196
208
|
onPipPlayPause: Record<string, never>;
|
|
197
209
|
onPipExpand: Record<string, never>;
|
|
198
210
|
onPipClose: Record<string, never>;
|
|
211
|
+
/**
|
|
212
|
+
* The user is leaving the app (home, recents, app switcher).
|
|
213
|
+
*
|
|
214
|
+
* A consumer that owns its own chrome over the picture uses this to
|
|
215
|
+
* remove that chrome and THEN enter Picture-in-Picture itself. The
|
|
216
|
+
* order is not negotiable: an Activity in PiP does not redraw, so
|
|
217
|
+
* whatever its window contained at the moment of the transition is
|
|
218
|
+
* what the PiP window keeps showing — frozen, dead and scaled down.
|
|
219
|
+
* See `PipManager`'s note on the same thing.
|
|
220
|
+
*/
|
|
221
|
+
onUserLeaveHint: Record<string, never>;
|
|
199
222
|
}
|
|
200
223
|
|
|
201
224
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -1051,8 +1074,15 @@ export function removeAllListeners(event?: PlayerEventName): void {
|
|
|
1051
1074
|
}
|
|
1052
1075
|
}
|
|
1053
1076
|
|
|
1054
|
-
/**
|
|
1055
|
-
|
|
1077
|
+
/**
|
|
1078
|
+
* All 27 player event names — the ONE owner of this list.
|
|
1079
|
+
*
|
|
1080
|
+
* `<PlayerProvider>` imports it to subscribe to every event on mount,
|
|
1081
|
+
* `removeAllListeners()` iterates it when no event is named, and the
|
|
1082
|
+
* test suite derives its expectation from it. A second hand-written
|
|
1083
|
+
* copy of this list is how the count drifted in the first place.
|
|
1084
|
+
*/
|
|
1085
|
+
export const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
1056
1086
|
'onFileLoaded',
|
|
1057
1087
|
'onLoadRequested',
|
|
1058
1088
|
'onPlaybackStateChanged',
|
|
@@ -1079,4 +1109,5 @@ const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
|
1079
1109
|
'onPipPlayPause',
|
|
1080
1110
|
'onPipExpand',
|
|
1081
1111
|
'onPipClose',
|
|
1112
|
+
'onUserLeaveHint',
|
|
1082
1113
|
];
|
|
@@ -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 27 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 27 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/config.ts
CHANGED
|
@@ -51,7 +51,18 @@ export const DEFAULT_THEME: PlayerTheme = {
|
|
|
51
51
|
export interface PipConfig {
|
|
52
52
|
/** Master switch — when false, all PiP entry requests are ignored. */
|
|
53
53
|
enabled: boolean;
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* When true, the library reports that the user is leaving the app, through
|
|
56
|
+
* the `onUserLeaveHint` event, and the CONSUMER enters PiP itself.
|
|
57
|
+
*
|
|
58
|
+
* The library deliberately does NOT arm Android's own auto-enter switch
|
|
59
|
+
* (`PictureInPictureParams.Builder.setAutoEnterEnabled`): that makes the OS
|
|
60
|
+
* transition the Activity without giving the app a chance to remove its own
|
|
61
|
+
* chrome, and an Activity in Picture-in-Picture does not redraw — so the
|
|
62
|
+
* chrome is frozen into the PiP window as a dead layer. See the README's
|
|
63
|
+
* Picture-in-Picture section for the two lines of Kotlin and the JS that
|
|
64
|
+
* go with it.
|
|
65
|
+
*/
|
|
55
66
|
autoEnterOnLeave: boolean;
|
|
56
67
|
}
|
|
57
68
|
|