@simba-dev/react-native-media-player 3.1.0 → 3.3.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/CHANGELOG.md +197 -7
- package/README.md +109 -40
- package/android/src/main/java/com/simba/player/PipManager.kt +141 -132
- package/android/src/main/java/com/simba/player/PipNativeEntry.kt +108 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +748 -221
- package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +18 -1
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +25 -22
- package/src/types/config.ts +38 -9
- package/src/types/player.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,187 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.3.0] - 2026-11-04
|
|
3
|
+
|
|
4
|
+
### Fixed
|
|
5
|
+
|
|
6
|
+
- **The Picture-in-Picture window showed the app's full expanded chrome, scaled down.** The PiP
|
|
7
|
+
window opened, and the video played under it — but the header band, the scrub row with its frozen
|
|
8
|
+
clock, the ±10 buttons, the big pause button and the volume row were painted into the window
|
|
9
|
+
too, at a fraction of their size, and their buttons were dead. Measured on emulator-5554 (API
|
|
10
|
+
37) on 2026-11-03.
|
|
11
|
+
|
|
12
|
+
**3.2.0's claim is retracted.** 3.2.0 said the library hides the consumer's chrome on the HOME
|
|
13
|
+
path. It did hide it — natively, with `visibility = View.GONE` — but the hide **could not reach
|
|
14
|
+
the pixels**: `Activity.onUserLeaveHint()` is called as part of the Activity's PAUSE
|
|
15
|
+
transaction, and there is **no frame between the hide and the pause**. The PiP window is built
|
|
16
|
+
from the window's last rendered buffer, and that buffer still held the chrome. The chrome was
|
|
17
|
+
hidden and stayed visible.
|
|
18
|
+
|
|
19
|
+
Two mechanisms keep the app's chrome out of the PiP window now, and they are layered:
|
|
20
|
+
|
|
21
|
+
1. **The crop (primary).** The platform crops the app's window to the rect in
|
|
22
|
+
`PictureInPictureParams.setSourceRectHint(...)` and scales that crop into the PiP window. The
|
|
23
|
+
library now **commits** the params to the Activity with
|
|
24
|
+
`Activity.setPictureInPictureParams(...)` — early, and every time the picture's geometry,
|
|
25
|
+
the video's shape or the playback state changes — instead of handing them over only at the
|
|
26
|
+
entry moment. A source rect hint that is only handed over at the entry moment never crops
|
|
27
|
+
anything: the PiP window then shows the whole window, scaled down. Google's own
|
|
28
|
+
`androidx.core-pip` does exactly this — it tracks the player view's bounds and commits the
|
|
29
|
+
params as they change.
|
|
30
|
+
|
|
31
|
+
The hint is the region of the window the **video** occupies (the video's own frame inside
|
|
32
|
+
the picture box, letterboxed), not the picture box's rect — the box fills the screen, so
|
|
33
|
+
hinting the box crops the whole screen into the PiP window, chrome included.
|
|
34
|
+
|
|
35
|
+
2. **The hide (second line of defence).** The chrome the app draws *over* the video — the big
|
|
36
|
+
pause button, the scrub row — is inside the crop, so the crop cannot remove it. It is now
|
|
37
|
+
hidden from `onPictureInPictureModeChanged(true)`: after the platform has entered PiP, and
|
|
38
|
+
while the activity is "paused, but rendering", so the invalidation is drawn. A `nativeID`
|
|
39
|
+
that no view carries is no longer a refusal — it means the chrome is **already hidden**, and
|
|
40
|
+
the entry goes on.
|
|
41
|
+
|
|
42
|
+
- **The PiP action row was a second copy of the platform's own buttons.** The library's Expand
|
|
43
|
+
and Close actions are gone: the platform renders its own expand / close / settings affordances
|
|
44
|
+
in the PiP window, and the library's row duplicated them. The row now carries **exactly one**
|
|
45
|
+
action, play/pause, with a **state-driven icon** — the pause icon while the video is playing,
|
|
46
|
+
the play icon while it is paused — and the params are re-committed when the playback state
|
|
47
|
+
changes so the platform picks the new icon up.
|
|
48
|
+
|
|
49
|
+
- **The play/pause button went through JavaScript to pause the video.** The broadcast now
|
|
50
|
+
reaches the engine directly (`PlaybackHost` + `MPVLib`), the same way
|
|
51
|
+
`MediaPlaybackService`'s session callbacks drive playback. The old path was
|
|
52
|
+
broadcast → JS event → bridge → mpv, and this library's own code recorded why that shape is
|
|
53
|
+
fragile: "the broadcast can arrive after the JS bundle has unloaded". The `onPipPlayPause`
|
|
54
|
+
event still exists in the JS API for compatibility, but it is not the mechanism that pauses
|
|
55
|
+
playback.
|
|
56
|
+
|
|
57
|
+
- **The source rect hint was applied from Android 12 only.** `setSourceRectHint(Rect)` has been
|
|
58
|
+
available since API 26; react-native-video and expo-video both hand it over from API 26.
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
|
|
62
|
+
- **Android 12+ uses the platform's own auto-enter switch.** The library arms
|
|
63
|
+
`setAutoEnterEnabled(true)` — but **only while media is loaded**, and disarms it when playback
|
|
64
|
+
stops, so browsing the Home screen with nothing playing cannot throw the user into a PiP
|
|
65
|
+
window. While auto-enter is armed, `notifyUserLeaveHint(activity)` is a logged no-op: ATMS
|
|
66
|
+
refuses an explicit `enterPictureInPictureMode()` while auto-enter is enabled ("auto-enter
|
|
67
|
+
should take in place instead"). The explicit entry is kept for API 24–30. The consumer's
|
|
68
|
+
Activity keeps calling `MpvBridgeModule.notifyUserLeaveHint(this)` from `onUserLeaveHint()` —
|
|
69
|
+
unchanged, and correct on every API level.
|
|
70
|
+
|
|
71
|
+
### Documentation
|
|
72
|
+
|
|
73
|
+
- Every sentence in this library that said React Native pauses its own scheduler together with the
|
|
74
|
+
Activity was **mechanically wrong**, and a wrong reason sends the next reader looking for the
|
|
75
|
+
fix in the wrong place. React Native freezes in **two** ways while the Activity is paused:
|
|
76
|
+
`FabricUIManager.onHostPause()` removes the DISPATCH_UI frame callback, so mount items are
|
|
77
|
+
never applied to native views, and `JavaTimerManager.onHostPause()` freezes the timer registry,
|
|
78
|
+
so `requestAnimationFrame` never fires. The JS runtime itself keeps running. Corrected in
|
|
79
|
+
`MpvBridgeModule.kt`, `PipManager.kt`, `PipNativeEntry.kt`, `MpvPlayerModule.ts` and
|
|
80
|
+
`config.ts`.
|
|
81
|
+
|
|
82
|
+
- The claim that an Activity in Picture-in-Picture never repaints its window was corrected too:
|
|
83
|
+
the app window's **UI layer** stops producing frames while it is paused, while a `SurfaceView`
|
|
84
|
+
keeps compositing.
|
|
85
|
+
|
|
86
|
+
## [3.2.0] - 2026-11-03
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- **Pressing HOME opened no Picture-in-Picture window at all.** The BUTTON path worked and was
|
|
91
|
+
proven on emulator-5554 (API 37): the app unmounted its chrome in React, waited one animation
|
|
92
|
+
frame, and then asked for the window. The HOME path did not — pressing HOME opened no PiP
|
|
93
|
+
window, and on return the screen was black and chromeless with the consumer's store stuck at
|
|
94
|
+
`pipActive=true` / `pipEntryRequested=true`.
|
|
95
|
+
|
|
96
|
+
The cause was measured, not guessed. `Activity.onUserLeaveHint()` fired and the JS handler ran
|
|
97
|
+
immediately, but the effect that would have driven the entry ran **5.7 s late** and the
|
|
98
|
+
`requestAnimationFrame` **never fired**. React Native freezes in TWO ways while the Activity is
|
|
99
|
+
paused — `FabricUIManager.onHostPause()` removes the DISPATCH_UI frame callback, so mount items
|
|
100
|
+
are never applied to native views, and `JavaTimerManager.onHostPause()` freezes the timer
|
|
101
|
+
registry, so `requestAnimationFrame` never fires. The entry therefore has to be **native**,
|
|
102
|
+
inside `onUserLeaveHint()`, before `onPause`.
|
|
103
|
+
|
|
104
|
+
The library now performs the HOME-path entry itself:
|
|
105
|
+
|
|
106
|
+
- the PiP parameters are built by the same builder the JS path uses, and handed to the platform;
|
|
107
|
+
- the chrome is restored when Picture-in-Picture ends.
|
|
108
|
+
|
|
109
|
+
> **Superseded by 3.3.0.** This release made the PiP window **open** — it did not make the
|
|
110
|
+
> chrome go away. The chrome hide it added could not reach the pixels (there is no frame
|
|
111
|
+
> between the hide and the pause), and the source rect hint it passed at the entry moment never
|
|
112
|
+
> cropped the window. See the 3.3.0 entry above for what actually fixed it.
|
|
113
|
+
|
|
114
|
+
**Action required:** your Activity has to hand over the Activity.
|
|
115
|
+
|
|
116
|
+
```kotlin
|
|
117
|
+
// android/app/src/main/java/.../MainActivity.kt
|
|
118
|
+
override fun onUserLeaveHint() {
|
|
119
|
+
super.onUserLeaveHint()
|
|
120
|
+
com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint(this)
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
If your app draws its own chrome over the picture, give that view a `nativeID` and name it in
|
|
125
|
+
the config — the library hides that view, and nothing else:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
// the chrome root
|
|
129
|
+
<View nativeID="player-chrome" style={styles.chrome}>{/* your controls */}</View>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
<PlayerProvider
|
|
134
|
+
config={{pip: {enabled: true, autoEnterOnLeave: true, chromeNativeId: 'player-chrome'}}}>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The `nativeID` literal belongs to the consumer; the library never hardcodes one of its own.
|
|
138
|
+
Omit `chromeNativeId` if your app draws no chrome of its own — the library then enters
|
|
139
|
+
Picture-in-Picture without hiding anything.
|
|
140
|
+
|
|
141
|
+
### Removed
|
|
142
|
+
|
|
143
|
+
- **The `onUserLeaveHint` JS event.** The library now performs the HOME-path Picture-in-Picture
|
|
144
|
+
entry itself, so the event's only consumer — a consumer that drove the entry from JavaScript —
|
|
145
|
+
is the path the library took over. Leaving it would be a double-entry footgun: the OS would
|
|
146
|
+
refuse the second entry, the consumer would read that refusal as "PiP failed", and the chrome
|
|
147
|
+
would come back over a live PiP window.
|
|
148
|
+
|
|
149
|
+
This is a **public API removal**, which is why the release is 3.2.0 and not a patch. The bridge
|
|
150
|
+
now emits **26** named events; the list has one owner, `ALL_PLAYER_EVENTS` in
|
|
151
|
+
`src/bridge/MpvPlayerModule.ts`.
|
|
152
|
+
|
|
153
|
+
### Changed
|
|
154
|
+
|
|
155
|
+
- `MpvBridgeModule.notifyUserLeaveHint()` is now
|
|
156
|
+
`notifyUserLeaveHint(activity: Activity): Boolean`. It takes the Activity — the entry happens
|
|
157
|
+
on it — and returns the OS's own answer: `true` when the Activity entered Picture-in-Picture.
|
|
158
|
+
- **The PiP parameters have ONE owner.** The JS path (`enterPip`) and the native path
|
|
159
|
+
(`notifyUserLeaveHint`) build them through the same function, so the two cannot drift apart.
|
|
160
|
+
- The native path reports the title from mpv's `media-title` — which IS the title the consumer
|
|
161
|
+
supplied, because the library writes it as mpv's `force-media-title` before the load — and the
|
|
162
|
+
percentage from `time-pos` over `duration`, in the consumer's exact `"NN %"` format.
|
|
163
|
+
|
|
164
|
+
### Documentation
|
|
165
|
+
|
|
166
|
+
- Five places in this library still carried the false claim that an Activity in Picture-in-
|
|
167
|
+
Picture never repaints its window. The accurate statement is that the app window's **UI
|
|
168
|
+
layer** stops producing frames while the Activity is paused, while a `SurfaceView` keeps
|
|
169
|
+
compositing; and what stops is **REACT**, in two ways —
|
|
170
|
+
`FabricUIManager.onHostPause()` removes the DISPATCH_UI frame callback, and
|
|
171
|
+
`JavaTimerManager.onHostPause()` freezes the timer registry. Corrected in
|
|
172
|
+
`MpvBridgeModule.kt`, `CHANGELOG.md`, `README.md`, `MpvPlayerModule.ts` and `config.ts`.
|
|
173
|
+
|
|
174
|
+
### Added
|
|
175
|
+
|
|
176
|
+
- `PipConfig.chromeNativeId` — the `nativeID` of the consumer's chrome root, the view the
|
|
177
|
+
library hides natively on the HOME path.
|
|
178
|
+
- `PipNativeEntryTest` — 24 guard tests for the native HOME-path entry: the three refusals and
|
|
179
|
+
the order they come in, the chrome hidden with `GONE` **before** the PiP request, a refused
|
|
180
|
+
entry restoring the chrome, Picture-in-Picture ending restoring the chrome, the title read from
|
|
181
|
+
mpv's `media-title`, the percentage read from `time-pos`/`duration` in the consumer's exact
|
|
182
|
+
`"NN %"` format, one params builder for both paths, and the retired event's absence from the
|
|
183
|
+
event list.
|
|
184
|
+
|
|
2
185
|
## [3.1.0] - 2026-11-03
|
|
3
186
|
|
|
4
187
|
### Fixed
|
|
@@ -34,7 +217,7 @@
|
|
|
34
217
|
|
|
35
218
|
- The README described the **removed** mechanism: Android's own auto-enter switch, an API 31+
|
|
36
219
|
floor for auto-enter, a PiP action receiver "declared in the manifest", and 26 named
|
|
37
|
-
events where
|
|
220
|
+
events where the bridge had 27. It also pointed at a section for "the two lines of Kotlin and
|
|
38
221
|
the JS that goes with them" that did not contain them. All corrected; the auto-enter
|
|
39
222
|
section now carries the Kotlin and the JS a consumer needs, and explains why the consumer
|
|
40
223
|
performs the entry.
|
|
@@ -55,9 +238,11 @@
|
|
|
55
238
|
`PictureInPictureParams.Builder.setAutoEnterEnabled` (API 31+), which makes
|
|
56
239
|
the SYSTEM transition the activity into PiP when the user leaves the app,
|
|
57
240
|
with the consumer unable to do anything first. That is the wrong order for a
|
|
58
|
-
consumer that draws its own chrome over the picture, because
|
|
59
|
-
PiP
|
|
60
|
-
|
|
241
|
+
consumer that draws its own chrome over the picture, because an Activity in
|
|
242
|
+
PiP is "paused, but rendering" (AOSP) - what stops is REACT: React Native
|
|
243
|
+
freezes in two ways while the Activity is paused, so a React commit cannot
|
|
244
|
+
land and no frame is produced. So whatever its window held at the transition
|
|
245
|
+
is what the PiP window keeps showing. Measured on device on 2026-11-03, the
|
|
61
246
|
consumer's full expanded chrome was painted into the PiP window, its
|
|
62
247
|
buttons were dead, and its clock was frozen three minutes behind the real
|
|
63
248
|
position.
|
|
@@ -70,13 +255,18 @@
|
|
|
70
255
|
to the `onUserLeaveHint` event in JS; both are in the README's
|
|
71
256
|
Picture-in-Picture section.
|
|
72
257
|
|
|
258
|
+
(History: that event is **retired in 3.2.0**, and the entry itself moved
|
|
259
|
+
into the library — it is performed natively, inside `onUserLeaveHint()`,
|
|
260
|
+
because by then no React commit can land. See the 3.2.0 entry above.)
|
|
261
|
+
|
|
73
262
|
A side effect worth knowing: auto-enter now works on **every** API level.
|
|
74
263
|
The platform's switch never existed below Android 12; `onUserLeaveHint()`
|
|
75
264
|
does.
|
|
76
265
|
|
|
77
|
-
- **`onUserLeaveHint`
|
|
78
|
-
payload, and only when the auto-enter policy says yes — a consumer that
|
|
79
|
-
turned auto-enter off
|
|
266
|
+
- **`onUserLeaveHint` was the 27th player event.** It was emitted with an
|
|
267
|
+
empty payload, and only when the auto-enter policy says yes — a consumer that
|
|
268
|
+
turned auto-enter off was never asked to enter PiP. (The event was removed in
|
|
269
|
+
3.2.0; the bridge emits 26 events now.)
|
|
80
270
|
|
|
81
271
|
- **The bridge no longer stashes PiP params on the Activity.**
|
|
82
272
|
`Activity.setPictureInPictureParams` and the helper that pushed them
|
package/README.md
CHANGED
|
@@ -145,9 +145,9 @@ Your launcher Activity has to opt in:
|
|
|
145
145
|
`resizeableActivity="true"` is not optional. An Activity that is not resizeable cannot enter
|
|
146
146
|
Picture-in-Picture.
|
|
147
147
|
|
|
148
|
-
If `config.pip.autoEnterOnLeave` is on, the Activity also has to
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
If `config.pip.autoEnterOnLeave` is on, the Activity also has to hand the leave hint to the
|
|
149
|
+
library, which performs the Picture-in-Picture entry itself - see
|
|
150
|
+
[Picture-in-Picture](#picture-in-picture) for the two lines of Kotlin that go with it.
|
|
151
151
|
|
|
152
152
|
### Background audio
|
|
153
153
|
|
|
@@ -314,7 +314,7 @@ there is no library-owned overlay; the absolutely positioned `View` above is you
|
|
|
314
314
|
| Section | Fields | Default |
|
|
315
315
|
| --- | --- | --- |
|
|
316
316
|
| `theme` | `accent`, `background`, `text`, `textSecondary`, `surface`, `icon?` | `#FFD700`, `#121216`, `#FFFFFF`, `rgba(255,255,255,0.6)`, `rgba(255,255,255,0.1)` |
|
|
317
|
-
| `pip` | `enabled`, `autoEnterOnLeave` | `true`, `true
|
|
317
|
+
| `pip` | `enabled`, `autoEnterOnLeave`, `chromeNativeId?` | `true`, `true`, none |
|
|
318
318
|
| `hardwareDecoding` | `'auto' \| 'mediacodec' \| 'no'` | `'auto'` |
|
|
319
319
|
| `notifications` | `enabled`, `channelId` | `true`, `'simba_player_media'` |
|
|
320
320
|
| `audio` | `backgroundPlayback`, `respectAudioFocus` | `true`, `true` |
|
|
@@ -336,8 +336,8 @@ import {PlayerProvider} from '@simba-dev/react-native-media-player';
|
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
The resolved config is pushed to the native bridge as JSON. The native side acts on the PiP
|
|
339
|
-
section (
|
|
340
|
-
|
|
339
|
+
section (the auto-enter policy, and the `nativeID` of your chrome root); the remaining sections
|
|
340
|
+
are values your app reads back with `usePlayerConfig()` and applies itself.
|
|
341
341
|
`DEFAULT_PLAYER_CONFIG` and `DEFAULT_THEME` are exported if you would rather spread and patch.
|
|
342
342
|
|
|
343
343
|
|
|
@@ -359,48 +359,109 @@ declare `android:supportsPictureInPicture="true"` (see [Consumer setup](#consume
|
|
|
359
359
|
**Auto-enter on leave** is `config.pip.autoEnterOnLeave` (default `true`): it means "enter
|
|
360
360
|
Picture-in-Picture when the user leaves the app".
|
|
361
361
|
|
|
362
|
-
**
|
|
363
|
-
(`PictureInPictureParams.Builder.setAutoEnterEnabled`), because an Activity in
|
|
364
|
-
Picture-in-Picture does not redraw: whatever its window held at the moment of the transition is
|
|
365
|
-
what the PiP window keeps showing. Letting the OS transition the Activity first froze the
|
|
366
|
-
app's own controls into the PiP window, scaled down and dead - measured on device on
|
|
367
|
-
2026-11-03.
|
|
368
|
-
|
|
369
|
-
So the order is yours to keep: take your chrome off screen, let the frame that drew it go by,
|
|
370
|
-
and only then ask for the window. The library tells you WHEN, with two pieces.
|
|
362
|
+
**The library performs that entry, natively.** Two lines of Kotlin in your Activity:
|
|
371
363
|
|
|
372
364
|
```kotlin
|
|
373
365
|
// android/app/src/main/java/.../MainActivity.kt
|
|
374
366
|
override fun onUserLeaveHint() {
|
|
375
367
|
super.onUserLeaveHint()
|
|
376
|
-
com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint()
|
|
368
|
+
com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint(this)
|
|
377
369
|
}
|
|
378
370
|
```
|
|
379
371
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
372
|
+
The library then asks the OS for the window, hides your chrome, and brings your chrome back when
|
|
373
|
+
Picture-in-Picture ends. It returns whether the OS accepted the entry, so you can log it:
|
|
374
|
+
|
|
375
|
+
```kotlin
|
|
376
|
+
val entered = com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint(this)
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Why it is native, and why your Activity hands over the Activity
|
|
380
|
+
|
|
381
|
+
`Activity.onUserLeaveHint()` is the only hook Android gives you BEFORE the Activity is paused.
|
|
382
|
+
|
|
383
|
+
And by then, React Native has ALREADY frozen, in two ways: `FabricUIManager.onHostPause()`
|
|
384
|
+
removes the DISPATCH_UI frame callback, so mount items are never applied to native views, and
|
|
385
|
+
`JavaTimerManager.onHostPause()` freezes the timer registry, so `requestAnimationFrame` never
|
|
386
|
+
fires. The JS runtime itself keeps running. Measured on emulator-5554 (API 37) on 2026-11-03: the
|
|
387
|
+
JS handler ran immediately, the effect that would have driven the entry ran **5.7 s late**, and
|
|
388
|
+
the `requestAnimationFrame` **never fired**. So the entry has to happen in native code.
|
|
389
|
+
|
|
390
|
+
While the Activity is paused, the app window's **UI layer** stops producing frames, while a
|
|
391
|
+
`SurfaceView` keeps compositing. That is why the chrome is hidden from
|
|
392
|
+
`onPictureInPictureModeChanged(true)` and not from `onUserLeaveHint()`: `onUserLeaveHint()` is
|
|
393
|
+
called as part of the Activity's PAUSE transaction, and there is **no frame between the hide and
|
|
394
|
+
the pause** — a hide applied there never reaches the pixels. (The 3.2.0 release claimed otherwise;
|
|
395
|
+
the 3.3.0 release retracted it.)
|
|
396
|
+
|
|
397
|
+
### How your chrome is kept out of the PiP window
|
|
398
|
+
|
|
399
|
+
Two mechanisms, layered:
|
|
400
|
+
|
|
401
|
+
1. **The crop (primary).** The platform crops your window to the rect in
|
|
402
|
+
`PictureInPictureParams.setSourceRectHint(...)` and scales that crop into the PiP window. The
|
|
403
|
+
library **commits** the params to your Activity with
|
|
404
|
+
`Activity.setPictureInPictureParams(...)` — early, and again whenever the picture's geometry,
|
|
405
|
+
the video's shape or the playback state changes — because the platform builds the PiP window
|
|
406
|
+
from the LAST COMMITTED params. A hint handed over only at the entry moment never crops
|
|
407
|
+
anything, and the PiP window then shows your whole window, scaled down.
|
|
408
|
+
2. **The hide (second line of defence).** The chrome you draw *over* the video is inside the
|
|
409
|
+
crop, so the crop cannot remove it. The library hides your chrome root when Picture-in-
|
|
410
|
+
Picture starts.
|
|
411
|
+
|
|
412
|
+
### Telling the library which view is your chrome
|
|
413
|
+
|
|
414
|
+
If your app draws its own chrome over the picture, give that view a `nativeID` and tell the library
|
|
415
|
+
about it:
|
|
416
|
+
|
|
417
|
+
```tsx
|
|
418
|
+
// the consumer's JS - the chrome root
|
|
419
|
+
<View nativeID="player-chrome" style={styles.chrome}>
|
|
420
|
+
{/* your controls */}
|
|
421
|
+
</View>
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
```tsx
|
|
425
|
+
// the consumer's config
|
|
426
|
+
<PlayerProvider
|
|
427
|
+
config={{
|
|
428
|
+
pip: {enabled: true, autoEnterOnLeave: true, chromeNativeId: 'player-chrome'},
|
|
429
|
+
}}>
|
|
430
|
+
<App />
|
|
431
|
+
</PlayerProvider>
|
|
392
432
|
```
|
|
393
433
|
|
|
394
|
-
|
|
395
|
-
|
|
434
|
+
The library finds that view with React Native's own lookup (`ReactFindViewUtil.findView`), under
|
|
435
|
+
your Activity's window decor view, and hides it natively when Picture-in-Picture starts. The
|
|
436
|
+
`nativeID` literal is yours - the library never hardcodes one of its own.
|
|
437
|
+
|
|
438
|
+
Omit `chromeNativeId` if your app draws no chrome of its own: the library then enters
|
|
439
|
+
Picture-in-Picture without hiding anything.
|
|
440
|
+
|
|
441
|
+
**If the `nativeID` is set and no view carries it, the chrome is already hidden** - your own
|
|
442
|
+
button path unmounts it in React before it asks for the window - so the library logs that and
|
|
443
|
+
carries on. It never refuses the entry over a missing view.
|
|
444
|
+
|
|
445
|
+
On **Android 12+** the library also arms Android's own auto-enter switch
|
|
446
|
+
(`PictureInPictureParams.Builder.setAutoEnterEnabled`), but **only while media is loaded**, and it
|
|
447
|
+
disarms it when playback stops: browsing the Home screen with nothing playing must not throw you
|
|
448
|
+
into a PiP window of a stopped session. While the switch is armed, the OS performs the entry
|
|
449
|
+
itself, and the library's explicit `enterPictureInPictureMode()` call is skipped (the platform
|
|
450
|
+
refuses it while auto-enter is enabled).
|
|
451
|
+
|
|
452
|
+
This works on **every** Android version - `onUserLeaveHint()` exists everywhere, and the platform's
|
|
453
|
+
own switch never existed below Android 12.
|
|
396
454
|
|
|
397
455
|
The two PiP flags combine: auto-enter needs `pip.enabled` and `pip.autoEnterOnLeave` to both be
|
|
398
456
|
true.
|
|
399
457
|
|
|
400
458
|
|
|
401
|
-
The Picture-in-Picture action row has
|
|
402
|
-
|
|
403
|
-
|
|
459
|
+
The Picture-in-Picture action row has **one** button: **Play/Pause**, with a state-driven icon
|
|
460
|
+
(the pause icon while the video is playing, the play icon while it is paused). The platform
|
|
461
|
+
renders its own expand / close / settings affordances next to it. The button reaches the engine
|
|
462
|
+
directly - no JavaScript in the path - so it works even when the JS bundle is not running. The
|
|
463
|
+
`onPipPlayPause` event still exists in the API for compatibility, next to `onPipModeChanged`, but
|
|
464
|
+
it is not what pauses playback.
|
|
404
465
|
|
|
405
466
|
The media notification and lock screen are a separate surface. Its MediaSession advertises play,
|
|
406
467
|
pause, play/pause, stop, skip-to-next, skip-to-previous and seek-to, with title, artist and album
|
|
@@ -484,7 +545,7 @@ that position in that file. The defaults are 640×360 at quality 80, exported as
|
|
|
484
545
|
|
|
485
546
|
`getMpvPlayerModule()` returns the native module, or a no-op stand-in when the native side is
|
|
486
547
|
not wired (Jest, web previews) so consumer code stays renderable.
|
|
487
|
-
`subscribePlayerEvent(name, handler)` subscribes to one of the
|
|
548
|
+
`subscribePlayerEvent(name, handler)` subscribes to one of the 26 named events and returns an
|
|
488
549
|
unsubscribe function; `removeAllListeners()`, `setDebugLogging()` and
|
|
489
550
|
`dumpObservedProperties()` are also exported. The event names are typed as `PlayerEventName`.
|
|
490
551
|
|
|
@@ -501,14 +562,22 @@ before launching, and check `commands.isSurfaceMounted()`.
|
|
|
501
562
|
|
|
502
563
|
**Picture-in-Picture does not start.** The Activity is missing
|
|
503
564
|
`android:supportsPictureInPicture="true"` or `android:resizeableActivity="true"`. If auto-enter
|
|
504
|
-
on leave does nothing, the Activity is not
|
|
505
|
-
[Picture-in-Picture](#picture-in-picture).
|
|
565
|
+
on leave does nothing, the Activity is not calling `MpvBridgeModule.notifyUserLeaveHint(this)`
|
|
566
|
+
from `onUserLeaveHint()` - see [Picture-in-Picture](#picture-in-picture).
|
|
567
|
+
|
|
568
|
+
**The Picture-in-Picture window shows your app's chrome.** The platform crops your window to the
|
|
569
|
+
source rect hint in the COMMITTED PiP params, and the library commits them when the picture's
|
|
570
|
+
geometry, the video's shape or the playback state changes. If the crop is not happening, the
|
|
571
|
+
params are not being committed - the log says so (`companion.commitPipParams`). A `nativeID` in
|
|
572
|
+
your config that no view carries is NOT a refusal: the chrome is already hidden, and the library
|
|
573
|
+
says so in the log.
|
|
506
574
|
|
|
507
575
|
**The Picture-in-Picture action row shows three buttons and none of them work.** That was the
|
|
508
576
|
explicit-broadcast bug, fixed in 3.1.0: the action's PendingIntent named the receiver's
|
|
509
577
|
component, and an explicit broadcast is resolved through the manifest, where the receiver was
|
|
510
578
|
never declared. Check that you have not registered a receiver for the PiP actions yourself -
|
|
511
|
-
this package registers one, and a second registration delivers every action twice.
|
|
579
|
+
this package registers one, and a second registration delivers every action twice. Since 3.3.0
|
|
580
|
+
the row carries ONE button (play/pause) and the platform renders its own expand / close.
|
|
512
581
|
|
|
513
582
|
|
|
514
583
|
**Gradle fails with `libmpv.so not found at android/src/main/jniLibs/…`.** The postinstall
|
|
@@ -527,9 +596,9 @@ Call `commands.requestNotificationPermission()`.
|
|
|
527
596
|
|
|
528
597
|
- **Android only.** There is no iOS implementation.
|
|
529
598
|
- **No controls.** The library ships none; see [Controls](#controls).
|
|
530
|
-
- **Auto-enter on leave is
|
|
531
|
-
|
|
532
|
-
job
|
|
599
|
+
- **Auto-enter on leave is performed by the library, from your Activity.** Your Activity hands
|
|
600
|
+
over the leave hint and the library enters Picture-in-Picture natively, because by then no
|
|
601
|
+
React commit can land. Your app's own job is the `nativeID` of the chrome the library hides.
|
|
533
602
|
- **Most config sections are consumed in JavaScript.** The native side receives the resolved
|
|
534
603
|
config as JSON and acts on the PiP auto-enter policy; the rest are values your app reads back
|
|
535
604
|
through `usePlayerConfig()`.
|