@simba-dev/react-native-media-player 1.13.8 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -24
- package/android/src/main/java/com/simba/player/MediaPlaybackService.kt +20 -17
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +18 -307
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -20
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +36 -83
- package/src/bridge/NativeMpvPlayer.ts +15 -52
- package/src/bridge/loadAndPlay.ts +65 -0
- package/src/components/PlayerRoot.tsx +9 -13
- package/src/hooks/__tests__/useLaunchPlayback.test.tsx +44 -64
- package/src/hooks/useLaunchPlayback.ts +7 -11
- package/src/hooks/usePlayerActivity.ts +51 -60
- package/src/index.ts +5 -11
- package/src/types/__tests__/player.test.tsx +49 -17
- package/src/types/player.ts +28 -31
- package/android/src/main/java/com/simba/player/IMpvConfigProvider.kt +0 -36
- package/android/src/main/java/com/simba/player/IPipModeChangeEmitter.kt +0 -31
- package/android/src/main/java/com/simba/player/PlayerActivity.kt +0 -1626
- package/src/hooks/SimbaPlayerRoot.tsx +0 -128
- package/src/hooks/useIsPlayerActivity.ts +0 -61
- package/src/hooks/useLaunchParams.tsx +0 -126
package/README.md
CHANGED
|
@@ -51,8 +51,9 @@ A standalone NPM package that gives your React Native Android app a unified **vi
|
|
|
51
51
|
|
|
52
52
|
**Highlights:**
|
|
53
53
|
|
|
54
|
-
- **
|
|
54
|
+
- **One Activity** — playback renders into a `SurfaceView` your app already hosts. There is no second player window to declare, and no second Activity to keep in sync with yours.
|
|
55
55
|
- **Unified audio + video** — one engine, one set of controls. Audio files use the same `libmpv` instance with the surface hidden; no second player to maintain.
|
|
56
|
+
- **In-window video** — the surface is mounted once and resized to whatever rect you give it, so a docked mini player shows a **live picture**, not a poster frame.
|
|
56
57
|
- **Picture-in-Picture** — auto-enter on background (configurable), manual toggle, custom RemoteActions. Works correctly with the React Native view tree (no nested-SurfaceView surprises).
|
|
57
58
|
- **MediaSession + lock-screen controls** — title / artist / album on the lock screen; play / pause / skip / seek from Bluetooth headphones, wired headsets, Android Auto, etc.
|
|
58
59
|
- **Foreground service** — keeps audio alive when the activity backgrounds (Spotify-style behavior, opt-in).
|
|
@@ -75,21 +76,29 @@ Autolinking handles the rest — RN's `react-native config` will find the packag
|
|
|
75
76
|
|
|
76
77
|
### Consumer setup
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
Nothing to register. The package ships its own `<service>` and `<receiver>` declarations, and playback renders into **your** existing launcher Activity — there is no player Activity to declare.
|
|
80
|
+
|
|
81
|
+
Your launcher Activity does need the PiP prerequisites on Android 12+:
|
|
79
82
|
|
|
80
83
|
```xml
|
|
81
84
|
<!-- MOBILE_APP_REACT_NATIVE/android/app/src/main/AndroidManifest.xml -->
|
|
82
85
|
<activity
|
|
83
|
-
android:name="
|
|
86
|
+
android:name=".MainActivity"
|
|
84
87
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|navigation"
|
|
85
88
|
android:launchMode="singleTask"
|
|
86
89
|
android:supportsPictureInPicture="true"
|
|
87
90
|
android:resizeableActivity="true"
|
|
88
|
-
android:autoRemoveFromRecents="true"
|
|
89
91
|
android:theme="@style/AppTheme"
|
|
90
|
-
android:exported="
|
|
92
|
+
android:exported="true">
|
|
93
|
+
<intent-filter>
|
|
94
|
+
<action android:name="android.intent.action.MAIN" />
|
|
95
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
96
|
+
</intent-filter>
|
|
97
|
+
</activity>
|
|
91
98
|
```
|
|
92
99
|
|
|
100
|
+
`resizeableActivity="true"` is **not optional**. Its absence in an earlier release was misdiagnosed as "the SurfaceView is nested in React Native's view tree", which is what produced the original PiP black screen and the whole second-Activity architecture built on top of it.
|
|
101
|
+
|
|
93
102
|
If you plan to use **background audio**, declare the foreground-service permissions:
|
|
94
103
|
|
|
95
104
|
```xml
|
|
@@ -108,11 +117,10 @@ getMpvPlayerModule().requestNotificationPermission?.(); // graceful no-op on old
|
|
|
108
117
|
## Basic usage
|
|
109
118
|
|
|
110
119
|
```tsx
|
|
111
|
-
// App.tsx —
|
|
120
|
+
// App.tsx — one wrapper, one import, zero glue code
|
|
112
121
|
import React from 'react';
|
|
113
122
|
import {
|
|
114
123
|
SimbaPlayer,
|
|
115
|
-
SimbaPlayerRoot,
|
|
116
124
|
useOpenFromUrl,
|
|
117
125
|
} from '@simba-dev/react-native-media-player';
|
|
118
126
|
|
|
@@ -137,17 +145,13 @@ function AppContent() {
|
|
|
137
145
|
return () => sub.remove();
|
|
138
146
|
}, [openFromUrl]);
|
|
139
147
|
|
|
140
|
-
|
|
141
|
-
// (renders <PlayerRoot /> when launchParams is set, otherwise children).
|
|
142
|
-
return (
|
|
143
|
-
<SimbaPlayerRoot>
|
|
144
|
-
<YourNavigator />
|
|
145
|
-
</SimbaPlayerRoot>
|
|
146
|
-
);
|
|
148
|
+
return <YourNavigator />;
|
|
147
149
|
}
|
|
148
150
|
```
|
|
149
151
|
|
|
150
|
-
That's it — `<SimbaPlayer>` is the one-import, one-wrapper integration point. It composes the `PlayerProvider` (config + state) and `PlayerResumeProvider` (bookmark-aware resume lookup).
|
|
152
|
+
That's it — `<SimbaPlayer>` is the one-import, one-wrapper integration point. It composes the `PlayerProvider` (config + state) and `PlayerResumeProvider` (bookmark-aware resume lookup). `useOpenFromUrl()` absorbs the deep-link URI-scheme filter + title-derivation + extension-classification. `getResumePosition` is the function-prop shape for the resume lookup.
|
|
153
|
+
|
|
154
|
+
To play media in-window, drive it with `useLaunchPlayback(payload)` from your own tree — it loads the payload into the surface you have mounted, exactly once per launch identity. There is no activity branch to switch on, because there is no second Activity.
|
|
151
155
|
|
|
152
156
|
### Per-screen usage (V15+)
|
|
153
157
|
|
|
@@ -199,7 +203,8 @@ function TrackRow({ track }) {
|
|
|
199
203
|
</Pressable>
|
|
200
204
|
);
|
|
201
205
|
}
|
|
202
|
-
//
|
|
206
|
+
// Audio starts the foreground service; video loads into the surface
|
|
207
|
+
// your app already has mounted. Either way you own the chrome.
|
|
203
208
|
```
|
|
204
209
|
|
|
205
210
|
### Resume-aware openPlayer (with bookmarks)
|
|
@@ -441,8 +446,7 @@ Every public export lives in [`src/index.ts`](./src/index.ts). The **V13+ surfac
|
|
|
441
446
|
|
|
442
447
|
| Component | Purpose |
|
|
443
448
|
|---|---|
|
|
444
|
-
| `<SimbaPlayer>` | **One-import, one-wrapper integration.** Composes `PlayerProvider` + `PlayerResumeProvider`.
|
|
445
|
-
| **`<SimbaPlayerRoot>`** | **V14 — activity-branch wrapper.** Calls `useLaunchParams()` internally; renders `<PlayerRoot />` when the activity was launched with playback params, otherwise renders its `children`. Replaces the V13 `if (launchParams) return <PlayerRoot />` boilerplate. |
|
|
449
|
+
| `<SimbaPlayer>` | **One-import, one-wrapper integration.** Composes `PlayerProvider` + `PlayerResumeProvider`. Adds the `getResumePosition` function prop (alongside the legacy `lookup` object prop). Use this at the app root. |
|
|
446
450
|
| `<PlayerRoot>` | Renders `<PlayerSurface>` + the controls overlay (default `<DefaultControls>` or custom via `renderControls`). |
|
|
447
451
|
| `<PlayerSurface>` | `<View flex:1>` placeholder for the native SurfaceView. a11y-hidden. |
|
|
448
452
|
| `<DefaultControls>` | Pre-built controls (top bar, scrubber, transport, auto-hide). |
|
|
@@ -452,7 +456,7 @@ Every public export lives in [`src/index.ts`](./src/index.ts). The **V13+ surfac
|
|
|
452
456
|
|
|
453
457
|
| Hook | Returns | Throws outside provider? |
|
|
454
458
|
|---|---|---|
|
|
455
|
-
| `usePlayerActivity()` | `{ openPlayer(opts)
|
|
459
|
+
| `usePlayerActivity()` | `{ openPlayer(opts) }` - `audio` starts the foreground service; `video` loads into the mounted surface and resolves `false` if there is none. | ❌ No (no-op fallback) |
|
|
456
460
|
| `useOpenWithResume()` | `(opts: OpenPlayerOptions & { resumeId? }) => Promise<boolean>` | ❌ No (no-op lookup) |
|
|
457
461
|
| **`useOpenFromUrl()`** | **`(uri: string) => Promise<boolean>`** — **deep-link helper** that filters `content://` + `file://` URIs, derives a title from the basename, classifies audio/video by extension, and forwards to `useOpenWithResume().openPlayer(...)` | ❌ No |
|
|
458
462
|
| **`useOpenPlaylist()`** | __V15 — `{ openPlaylist(entries, opts) }` — "play all from a list" two-step absorption. `opts: { type?, startIndex?, startPositionMs?, shuffle?, startExtras? }`__ | ❌ No |
|
|
@@ -464,7 +468,6 @@ Every public export lives in [`src/index.ts`](./src/index.ts). The **V13+ surfac
|
|
|
464
468
|
| __`useIsLiked(uri)` / `useToggleLiked()`__ | __V15 — per-file "liked" state (Record<uri, boolean>) + toggle action.__ | ❌ No |
|
|
465
469
|
| __`useShuffle()` / `useShuffleEnabled()`__ | __V15 — shuffle flag + toggle action.__ | ❌ No |
|
|
466
470
|
| `usePlayItem()` | `(item, opts) => Promise<boolean>` | ❌ No (sugar on `useOpenWithResume`) |
|
|
467
|
-
| `useLaunchParams()` | `LaunchParams \| null` | ❌ No (returns null) |
|
|
468
471
|
| `usePlayer()` | `{ state: PlayerState, commands: PlayerCommands, progress: PlayerProgress }` | ❌ No (returns defaults) |
|
|
469
472
|
| `usePlayerProgress()` | `{ positionMs, durationMs, isBuffering, isSeeking, seekable, cacheRanges, cacheFill }` | ❌ No (returns 0/0) |
|
|
470
473
|
| `usePlayerConfig()` | `ResolvedPlayerConfig` | ✅ Yes (programmer error) |
|
|
@@ -477,14 +480,13 @@ Every public export lives in [`src/index.ts`](./src/index.ts). The **V13+ surfac
|
|
|
477
480
|
|---|---|
|
|
478
481
|
| `PlayerState` | 20 fields: `isPlaying`, `title`, `artist`, `album`, `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `volume`, `isMuted`, `speed`, `loopMode`, `playlist`, `currentIndex`, `tracks`, `chapters`, `currentChapter`, `videoParams`, `error` |
|
|
479
482
|
| `PlayerProgress` | 7 fields: `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `cacheRanges`, `cacheFill` |
|
|
480
|
-
| `PlayerCommands` | 38 methods: `play`, `pause`, `seek`, `skipBackward`, `skipForward`, `togglePlayPause`, `stop`, `seekBy`, `seekToChapter`, `next`, `previous`, `setVolume`, `setMuted`, `toggleMute`, `setSpeed`, `setLoopMode`, `loadFile`, `loadPlaylist`, `playlistRemove`, `shuffle`, `clear`, `cycleTrack`, `setTrack`, `enterPip`, `exitPip`, `exitPipAndFinish`, `setKeepScreenOn`, `setOrientation`, `setImmersive`, `setScreenBrightness`, `requestNotificationPermission`, `openPlayer`, `
|
|
483
|
+
| `PlayerCommands` | 38 methods: `play`, `pause`, `seek`, `skipBackward`, `skipForward`, `togglePlayPause`, `stop`, `seekBy`, `seekToChapter`, `next`, `previous`, `setVolume`, `setMuted`, `toggleMute`, `setSpeed`, `setLoopMode`, `loadFile`, `loadPlaylist`, `playlistRemove`, `shuffle`, `clear`, `cycleTrack`, `setTrack`, `enterPip`, `exitPip`, `exitPipAndFinish`, `setKeepScreenOn`, `setOrientation`, `setImmersive`, `setScreenBrightness`, `requestNotificationPermission`, `openPlayer`, `getProperty`, `setProperty`, `observeProperty`, `unobserveProperty`, `grantPersistablePermission`, `verifyContentUri` |
|
|
481
484
|
| `OpenPlayerOptions` | `{ uri, title, type: 'video' \| 'audio', startPositionMs? }` — the V13 `openPlayer` arg shape (replaces V11's positional args) |
|
|
482
|
-
| `LaunchParams` | `{ uri, title, type, startPositionMs }`
|
|
485
|
+
| `LaunchParams` | `{ uri, title, type, startPositionMs, requestId? }` - one playback launch payload. Pass it to `useLaunchPlayback(...)` to load it in-window. `requestId` gives the launch a unique identity so re-launching the same file at the same position still reloads. |
|
|
483
486
|
| `ContentKind` | `'video' \| 'audio' \| 'music' \| 'movie' \| 'podcast' \| 'live-tv' \| 'radio' \| 'audiobook' \| 'archive-audio' \| 'episode' \| 'video-file' \| string` |
|
|
484
487
|
| `PlayerResumeLookup` | `{ getResumePosition(itemId: string): number \| undefined }` — adapter for the bookmark-aware resume lookup |
|
|
485
488
|
| **`GetResumePosition`** | **V14 — `(itemId: string) => number \| undefined`** — the function reference shape for `<SimbaPlayer getResumePosition={...}>` |
|
|
486
489
|
| `SimbaPlayerProps` | `{ config?, lookup?, getResumePosition?, children }` — V14 adds `getResumePosition` (function prop, recommended). If both `lookup` and `getResumePosition` are passed, `getResumePosition` wins. |
|
|
487
|
-
| **`SimbaPlayerRootProps`** | **V14 — `{ children: React.ReactNode }`** — the children are rendered when the activity was launched WITHOUT playback params |
|
|
488
490
|
| `MpvPlayerModuleBridge` | Typed view of the native module (78 methods) |
|
|
489
491
|
| `PlayerConfig`, `ResolvedPlayerConfig`, `PlayerTheme`, `PipConfig`, `AudioConfig`, `SubtitleConfig`, `NotificationConfig`, `DebugConfig`, `HardwareDecodingPolicy` | V12 surface — same as before |
|
|
490
492
|
| `MpvTrack`, `MpvChapter`, `MpvFileInfo`, `MpvVideoParams`, `MpvAudioDevice`, `MpvPlaybackState`, `MpvLoopMode`, `MpvEventName`, `MpvEvents`, `MpvEventPayloads`, `PlayerEventName`, `PlayerEventPayloads` | Low-level mpv types |
|
|
@@ -614,7 +616,7 @@ When the system signals memory pressure via `ComponentCallbacks2.onTrimMemory()`
|
|
|
614
616
|
| `TRIM_MEMORY_BACKGROUND` | 10 |
|
|
615
617
|
| `TRIM_MEMORY_COMPLETE` | 0 |
|
|
616
618
|
|
|
617
|
-
No configuration needed — the bridge
|
|
619
|
+
No configuration needed — the bridge adjusts `mpv.setPropertyString('cache-secs', ...)` from the host Activity's own `onTrimMemory` callbacks.
|
|
618
620
|
|
|
619
621
|
#### Native module init log
|
|
620
622
|
|
|
@@ -147,8 +147,10 @@ class MediaPlaybackService : Service() {
|
|
|
147
147
|
* This is a convenience handle, not an ownership mechanism: the
|
|
148
148
|
* session and the notification are created and released by the
|
|
149
149
|
* Service's own lifecycle regardless of who holds a reference.
|
|
150
|
-
* It
|
|
151
|
-
*
|
|
150
|
+
* It is the process-global the module reads across Activity
|
|
151
|
+
* boundaries, which is the same shape `currentActivityIsPlayer`
|
|
152
|
+
* used to have before V21 F5 deleted that flag along with the
|
|
153
|
+
* second Activity it identified.
|
|
152
154
|
*/
|
|
153
155
|
@Volatile
|
|
154
156
|
private var instance: MediaPlaybackService? = null
|
|
@@ -201,7 +203,7 @@ class MediaPlaybackService : Service() {
|
|
|
201
203
|
*
|
|
202
204
|
* ## Why this is resolved and not written down
|
|
203
205
|
*
|
|
204
|
-
*
|
|
206
|
+
* This and the session-activity [PendingIntent] used to name
|
|
205
207
|
* their target as the string literal `"com.simba.player.PlayerActivity"`.
|
|
206
208
|
* A hardcoded component name is the one kind of dependency that
|
|
207
209
|
* survives every gate: it typechecks, it compiles, it packages, and
|
|
@@ -210,23 +212,24 @@ class MediaPlaybackService : Service() {
|
|
|
210
212
|
* at build time, which is exactly why it has to not exist.
|
|
211
213
|
*
|
|
212
214
|
* It also made the V21 collapse unsafe *by construction*: the
|
|
213
|
-
* library was naming a class the application
|
|
214
|
-
* deleting it would have shipped a green build with two dead
|
|
215
|
-
* notification paths in it.
|
|
215
|
+
* library was naming a class the application was about to delete,
|
|
216
|
+
* so deleting it would have shipped a green build with two dead
|
|
217
|
+
* notification paths in it. That class is now gone.
|
|
216
218
|
*
|
|
217
|
-
* The player host IS the application entry point
|
|
218
|
-
* in
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
219
|
+
* The player host IS the application entry point — playback lives
|
|
220
|
+
* in the single Activity the launcher already opens — so rather
|
|
221
|
+
* than assert a name and keep it in sync, ask Android which
|
|
222
|
+
* component the launcher icon resolves to. `CATEGORY_LAUNCHER` +
|
|
223
|
+
* `setPackage` is the platform's own answer to "what does
|
|
224
|
+
* launching this app do", scoped to this package so it cannot pick
|
|
225
|
+
* up another app's activity.
|
|
223
226
|
*
|
|
224
227
|
* Returns null when the package declares no launchable activity.
|
|
225
228
|
* Callers must degrade rather than invent a component — a
|
|
226
229
|
* [PendingIntent] aimed at a class that may not exist is precisely
|
|
227
230
|
* the bug this replaces.
|
|
228
231
|
*/
|
|
229
|
-
private fun
|
|
232
|
+
private fun hostActivityIntent(context: Context): Intent? {
|
|
230
233
|
val pm = context.packageManager
|
|
231
234
|
val launchIntent = Intent(Intent.ACTION_MAIN)
|
|
232
235
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
@@ -265,11 +268,11 @@ class MediaPlaybackService : Service() {
|
|
|
265
268
|
* its task is still alive, or launches a fresh instance otherwise.
|
|
266
269
|
*
|
|
267
270
|
* Null when the package declares no launchable activity; see
|
|
268
|
-
* [
|
|
271
|
+
* [hostActivityIntent] for why that degrades instead of
|
|
269
272
|
* guessing a component.
|
|
270
273
|
*/
|
|
271
274
|
private fun buildContentIntent(context: Context): PendingIntent? {
|
|
272
|
-
val intent =
|
|
275
|
+
val intent = hostActivityIntent(context) ?: return null
|
|
273
276
|
return PendingIntent.getActivity(
|
|
274
277
|
context,
|
|
275
278
|
0,
|
|
@@ -457,11 +460,11 @@ class MediaPlaybackService : Service() {
|
|
|
457
460
|
// Tapping the lock-screen widget should surface the player.
|
|
458
461
|
//
|
|
459
462
|
// Resolved from the manifest rather than hardcoded — see
|
|
460
|
-
// `
|
|
463
|
+
// `hostActivityIntent`. `setSessionActivity(null)` is the
|
|
461
464
|
// documented "this session has no UI target" value, so an
|
|
462
465
|
// unresolvable host degrades to a widget that simply does not
|
|
463
466
|
// offer a tap target instead of one that throws when tapped.
|
|
464
|
-
|
|
467
|
+
hostActivityIntent(this@MediaPlaybackService)?.let { hostIntent ->
|
|
465
468
|
setSessionActivity(
|
|
466
469
|
PendingIntent.getActivity(
|
|
467
470
|
this@MediaPlaybackService,
|
|
@@ -19,8 +19,6 @@ import com.facebook.react.bridge.UiThreadUtil
|
|
|
19
19
|
import com.facebook.react.module.annotations.ReactModule
|
|
20
20
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
21
21
|
import com.facebook.fbreact.specs.NativeMpvPlayerSpec
|
|
22
|
-
import com.simba.player.IMpvConfigProvider
|
|
23
|
-
import com.simba.player.IPipModeChangeEmitter
|
|
24
22
|
import com.simba.player.PlaybackHost
|
|
25
23
|
import org.json.JSONArray
|
|
26
24
|
import org.json.JSONObject
|
|
@@ -33,9 +31,7 @@ import org.json.JSONObject
|
|
|
33
31
|
*/
|
|
34
32
|
@ReactModule(name = MpvBridgeModule.NAME)
|
|
35
33
|
class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
36
|
-
NativeMpvPlayerSpec(reactContext)
|
|
37
|
-
IMpvConfigProvider,
|
|
38
|
-
IPipModeChangeEmitter {
|
|
34
|
+
NativeMpvPlayerSpec(reactContext) {
|
|
39
35
|
|
|
40
36
|
companion object {
|
|
41
37
|
const val NAME = "MpvPlayerModule"
|
|
@@ -83,30 +79,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
83
79
|
// the branch away in release entirely.
|
|
84
80
|
private const val TRACE_PROPERTY_EVENTS = false
|
|
85
81
|
|
|
86
|
-
// V22.0.0 / 1.5.10 (D-034): activity-aware launchParams guard.
|
|
87
|
-
//
|
|
88
|
-
// Background: `lastLaunchParams` (declared further down) is the
|
|
89
|
-
// canonical handoff from `openPlayer(...)` to the next
|
|
90
|
-
// `PlayerActivity` mount. The previous architecture had
|
|
91
|
-
// `useLaunchParams()` consume it from BOTH MainActivity's React
|
|
92
|
-
// tree and PlayerActivity's React tree - both activities mount
|
|
93
|
-
// the same JS App and both wrap in `<SimbaPlayerRoot>` which
|
|
94
|
-
// calls the hook on mount. Result on cold start: stale
|
|
95
|
-
// lastLaunchParams from a prior `openPlayer` call got consumed
|
|
96
|
-
// by MainActivity's tree, and `<PlayerRoot />` got rendered over
|
|
97
|
-
// the Home screen (the V22 user regression).
|
|
98
|
-
//
|
|
99
|
-
// The fix: PlayerActivity's `onCreate` sets this flag to
|
|
100
|
-
// `true` and `onDestroy` resets to `false`. `useLaunchParams()`
|
|
101
|
-
// consults it via the synchronous `isCurrentActivityPlayer()`
|
|
102
|
-
// bridge method and returns `null` (without touching
|
|
103
|
-
// lastLaunchParams) when we are in any non-PlayerActivity host.
|
|
104
|
-
// The flag is process-wide (companion object), so React tree
|
|
105
|
-
// boundaries don't matter.
|
|
106
|
-
@Volatile
|
|
107
|
-
@JvmStatic
|
|
108
|
-
var currentActivityIsPlayer: Boolean = false
|
|
109
|
-
|
|
110
82
|
// Holds the ReactApplicationContext from RN init time so non-module
|
|
111
83
|
// call sites (e.g. MainActivity.onPictureInPictureModeChanged) can
|
|
112
84
|
// emit DeviceEventManagerModule events. Bridgeless RN: MainActivity's
|
|
@@ -126,73 +98,22 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
126
98
|
var debugLoggingEnabled: Boolean = false
|
|
127
99
|
private set
|
|
128
100
|
|
|
129
|
-
/**
|
|
130
|
-
* Phase 13: snapshot of the launch params the most recent
|
|
131
|
-
* [openPlayer] call handed to `PlayerActivity`. Populated
|
|
132
|
-
* before `startActivity` and consumed (cleared) by the next
|
|
133
|
-
* [getLaunchParams] call. PlayerActivity's JS calls
|
|
134
|
-
* `getLaunchParams()` on mount to rebuild its PlaybackContext
|
|
135
|
-
* state — the launched activity's React context is fresh and
|
|
136
|
-
* has no MainActivity PlaybackContext state to inherit.
|
|
137
|
-
*/
|
|
138
|
-
@Volatile
|
|
139
|
-
private var lastLaunchParams: LaunchParams? = null
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* D-039: PlayerActivity is the source of truth for launch
|
|
143
|
-
* params read from its Intent extras, but the JS tree inside
|
|
144
|
-
* the launched activity reads them back via [getLaunchParams]
|
|
145
|
-
* which inspects [lastLaunchParams]. Without this push, any
|
|
146
|
-
* PlayerActivity launch that bypasses [openPlayer] (deep link,
|
|
147
|
-
* app shortcut, `am start`, ADB) leaves JS `getLaunchParams()`
|
|
148
|
-
* returning null and `<PlayerRoot />` renders the empty
|
|
149
|
-
* fallback. Populated from [com.simba.player.PlayerActivity.onCreate]
|
|
150
|
-
* immediately after the `launchUri` / `launchTitle` /
|
|
151
|
-
* `launchType` / `launchStartPositionMs` lazy vals are first
|
|
152
|
-
* touched. No-op if `uri` is blank — MainActivity (which has
|
|
153
|
-
* no player intent extras) won't accidentally clobber a real
|
|
154
|
-
* launch in flight.
|
|
155
|
-
*/
|
|
156
|
-
@JvmStatic
|
|
157
|
-
fun setLaunchParamsFromIntent(
|
|
158
|
-
uri: String,
|
|
159
|
-
title: String,
|
|
160
|
-
type: String,
|
|
161
|
-
startPositionMs: Long,
|
|
162
|
-
) {
|
|
163
|
-
if (uri.isBlank()) return
|
|
164
|
-
lastLaunchParams = LaunchParams(uri, title, type, startPositionMs)
|
|
165
|
-
Log.i(
|
|
166
|
-
TAG,
|
|
167
|
-
"[PlaybackTrace][Bridge][setLaunchParamsFromIntent] populated from Intent extras uri='$uri' type='$type' startMs=$startPositionMs",
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Phase 13.3: simple value class for the launch params
|
|
173
|
-
* cached for [getLaunchParams]. Mirrors the four intent
|
|
174
|
-
* extras that PlayerActivity reads from its own `by lazy {}`
|
|
175
|
-
* `launchUri` / `launchTitle` / `launchType` /
|
|
176
|
-
* `launchStartPositionMs` properties.
|
|
177
|
-
*/
|
|
178
|
-
data class LaunchParams(
|
|
179
|
-
val uri: String,
|
|
180
|
-
val title: String,
|
|
181
|
-
val type: String,
|
|
182
|
-
val startPositionMs: Long,
|
|
183
|
-
)
|
|
184
|
-
|
|
185
101
|
/**
|
|
186
102
|
* Phase 21: cached PlayerConfig pushed by `<PlayerProvider
|
|
187
103
|
* config={...}>` via `setConfig(configJson)`. Stored as a
|
|
188
|
-
* Kotlin Map so
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* read happens on the Android main thread.
|
|
104
|
+
* Kotlin Map so individual keys can be read without re-parsing
|
|
105
|
+
* JSON. `@Volatile` because the push happens on the React Native
|
|
106
|
+
* JS thread while a read happens on the Android main thread.
|
|
192
107
|
*
|
|
193
|
-
* `null` when no Provider has wrapped the consumer app's
|
|
194
|
-
*
|
|
195
|
-
*
|
|
108
|
+
* `null` when no Provider has wrapped the consumer app's root.
|
|
109
|
+
*
|
|
110
|
+
* V21 F5: this cache no longer has a reader. Its only consumer
|
|
111
|
+
* was `IMpvConfigProvider.getCurrentConfig()`, called from
|
|
112
|
+
* `PlayerActivity`, which is deleted along with both
|
|
113
|
+
* module-side cast interfaces it existed to serve. `setConfig`
|
|
114
|
+
* itself stays — it is live public API every `<PlayerProvider>`
|
|
115
|
+
* calls — so the value is written and currently unread. Decide
|
|
116
|
+
* what reads it before adding another writer.
|
|
196
117
|
*/
|
|
197
118
|
@Volatile
|
|
198
119
|
private var currentConfig: Map<String, Any?>? = null
|
|
@@ -268,18 +189,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
268
189
|
}
|
|
269
190
|
}
|
|
270
191
|
|
|
271
|
-
// ── IPipModeChangeEmitter (Phase 10) ────────────────────────────────
|
|
272
|
-
// Phase 10: PlayerActivity (in the module) cannot call
|
|
273
|
-
// `MpvBridgeModule.onPictureInPictureModeChanged` directly because
|
|
274
|
-
// of the Gradle module boundary. It looks us up via the React Native
|
|
275
|
-
// bridge (`getNativeModule("MpvPlayerModule") as? IPipModeChangeEmitter`)
|
|
276
|
-
// and calls this method. We delegate to the companion method so the
|
|
277
|
-
// single source of truth for PiP mode-change events stays in the
|
|
278
|
-
// companion (the JS event name + payload contract is defined there).
|
|
279
|
-
override fun emitPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
|
|
280
|
-
onPictureInPictureModeChanged(isInPictureInPictureMode)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
192
|
init {
|
|
284
193
|
// Capture the ReactApplicationContext for the companion sendEvent path.
|
|
285
194
|
// Phase 36: clear the static reference when the module is destroyed so
|
|
@@ -1621,27 +1530,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1621
1530
|
return if (nativePtr != 0L) MPVLib.nativeGetMuted(nativePtr) else false
|
|
1622
1531
|
}
|
|
1623
1532
|
|
|
1624
|
-
// V22.0.0 / 1.5.10 (D-034): activity-aware launchParams guard.
|
|
1625
|
-
//
|
|
1626
|
-
// Returns true while PlayerActivity is the foreground React host,
|
|
1627
|
-
// false otherwise (MainActivity foreground, no React host, or
|
|
1628
|
-
// about to attach). Mirrors the static
|
|
1629
|
-
// `MpvBridgeModule.currentActivityIsPlayer` which PlayerActivity
|
|
1630
|
-
// toggles in onCreate/onDestroy.
|
|
1631
|
-
//
|
|
1632
|
-
// Why a static companion flag rather than `getCurrentActivity()
|
|
1633
|
-
// is PlayerActivity`: in `newArchEnabled=true` bridgeless mode,
|
|
1634
|
-
// `getCurrentActivity()` can return null mid-attach (RN hasn't
|
|
1635
|
-
// finished initializing), and the JS render path needs an
|
|
1636
|
-
// authoritative answer the instant MainActivity's React tree
|
|
1637
|
-
// mounts. The static flag set in `Activity.onCreate` (before
|
|
1638
|
-
// React even renders) is always authoritative.
|
|
1639
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
1640
|
-
@Override
|
|
1641
|
-
override fun isCurrentActivityPlayer(): Boolean {
|
|
1642
|
-
return currentActivityIsPlayer
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
1533
|
// ── Lifecycle ──────────────────────────────────────────────────────────
|
|
1646
1534
|
|
|
1647
1535
|
private fun prepareMpvCaBundle(): String {
|
|
@@ -1833,132 +1721,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1833
1721
|
super.onCatalystInstanceDestroy()
|
|
1834
1722
|
}
|
|
1835
1723
|
|
|
1836
|
-
// ── PlayerActivity Launch (V12 Phase 3 + Phase 11) ─────────────────────
|
|
1837
|
-
// Hands off to the dedicated `com.simba.player.PlayerActivity` (which
|
|
1838
|
-
// lives in the `@simba/react-native-media-player` library module and
|
|
1839
|
-
// therefore cannot be referenced directly from this app-side class —
|
|
1840
|
-
// we go through the fully-qualified name on the Intent target).
|
|
1841
|
-
//
|
|
1842
|
-
// The `type` extra is the key new piece in Phase 11: it tells
|
|
1843
|
-
// PlayerActivity which rendering path to take. `"video"` mounts the
|
|
1844
|
-
// SurfaceView; `"audio"` will hide it (Phase 12) and surface an
|
|
1845
|
-
// audio-only UI (Phase 13). PlayerActivity.EXTRA_* / TYPE_* constants
|
|
1846
|
-
// are mirrored into the intent extras here so PlayerActivity can read
|
|
1847
|
-
// them back in `onCreate` via its `by lazy {}` launch params.
|
|
1848
|
-
//
|
|
1849
|
-
// Reject codes (matched by the TS Spec's `E_*` contract in
|
|
1850
|
-
// NativeMpvPlayer.ts):
|
|
1851
|
-
// • E_INVALID_TYPE — `type` is neither "video" nor "audio"
|
|
1852
|
-
// • E_AUDIO_REQUIRES_SERVICE — `type` IS "audio". V20 Phase C
|
|
1853
|
-
// narrowed this method to video only. Audio is no longer forced
|
|
1854
|
-
// into a window it has nothing to draw in; it goes through
|
|
1855
|
-
// [startAudioPlayback], which starts the media service with no
|
|
1856
|
-
// Activity at all. Rejecting rather than quietly still opening an
|
|
1857
|
-
// Activity is deliberate: a stale JS bundle sending "audio" here
|
|
1858
|
-
// gets a named, greppable failure instead of a full-screen blank
|
|
1859
|
-
// player with no notification and no media keys.
|
|
1860
|
-
// • E_NO_ACTIVITY — no current activity (RN bridge down)
|
|
1861
|
-
// • E_ACTIVITY_NOT_FOUND — PlayerActivity not declared in manifest
|
|
1862
|
-
// • E_SECURITY — manifest restriction refused the launch
|
|
1863
|
-
// • E_OPEN_PLAYER_FAILED — anything else (e.g. flag mismatch)
|
|
1864
|
-
@ReactMethod
|
|
1865
|
-
@Override
|
|
1866
|
-
override fun openPlayer(
|
|
1867
|
-
uri: String,
|
|
1868
|
-
title: String,
|
|
1869
|
-
type: String,
|
|
1870
|
-
startPositionMs: Double,
|
|
1871
|
-
promise: Promise,
|
|
1872
|
-
) {
|
|
1873
|
-
// V20 Phase C: audio no longer belongs here. See the docblock.
|
|
1874
|
-
if (type == com.simba.player.PlayerActivity.TYPE_AUDIO) {
|
|
1875
|
-
Log.w(TAG, "[PlaybackTrace][Bridge][openPlayer] type='audio' is no longer a window launch, rejecting E_AUDIO_REQUIRES_SERVICE")
|
|
1876
|
-
promise.reject(
|
|
1877
|
-
"E_AUDIO_REQUIRES_SERVICE",
|
|
1878
|
-
"openPlayer is video-only as of 1.13.0; audio must use startAudioPlayback() so it does not need a window",
|
|
1879
|
-
)
|
|
1880
|
-
return
|
|
1881
|
-
}
|
|
1882
|
-
// 3.3: validate `type` — defensive against the JS layer ever
|
|
1883
|
-
// passing a typo (the TS Spec already types it as the union
|
|
1884
|
-
// `'video' | 'audio'`, but a stale bundle could skip the check).
|
|
1885
|
-
if (type != com.simba.player.PlayerActivity.TYPE_VIDEO) {
|
|
1886
|
-
Log.w(TAG, "[PlaybackTrace][Bridge][openPlayer] invalid type='$type', rejecting with E_INVALID_TYPE")
|
|
1887
|
-
promise.reject("E_INVALID_TYPE", "type must be 'video', got '$type'")
|
|
1888
|
-
return
|
|
1889
|
-
}
|
|
1890
|
-
// 3.4: require a current activity. In bridgeless RN this is null
|
|
1891
|
-
// before the first activity attaches, after the last activity
|
|
1892
|
-
// detaches, or in headless contexts. Without an activity we
|
|
1893
|
-
// cannot launch PlayerActivity.
|
|
1894
|
-
val activity = getCurrentActivity() ?: run {
|
|
1895
|
-
Log.w(TAG, "[PlaybackTrace][Bridge][openPlayer] no current activity, rejecting with E_NO_ACTIVITY")
|
|
1896
|
-
promise.reject("E_NO_ACTIVITY", "no current activity available to launch PlayerActivity")
|
|
1897
|
-
return
|
|
1898
|
-
}
|
|
1899
|
-
// 3.5: build the intent. Title falls back to the URI when blank
|
|
1900
|
-
// so the notification / lock-screen widget always has a display
|
|
1901
|
-
// string.
|
|
1902
|
-
//
|
|
1903
|
-
// No intent flags are set, deliberately. An earlier version of this
|
|
1904
|
-
// comment said "we use FLAG_ACTIVITY_NEW_TASK because we are
|
|
1905
|
-
// launching from a non-Activity context ... the flag is harmless".
|
|
1906
|
-
// Both halves were wrong: we launch from `activity`, and the flag is
|
|
1907
|
-
// NOT harmless — it starts the target in a new task, which breaks
|
|
1908
|
-
// the `singleTask` reuse that keeps a second `openPlayer` from
|
|
1909
|
-
// stacking a duplicate player window, and leaves the video in a task
|
|
1910
|
-
// the user's back gesture does not return from.
|
|
1911
|
-
//
|
|
1912
|
-
// If this ever does need to launch without an Activity, the flag
|
|
1913
|
-
// belongs there — and the task-affinity consequences need dealing
|
|
1914
|
-
// with, not waving through as "harmless".
|
|
1915
|
-
val resolvedTitle = title.takeIf { it.isNotBlank() } ?: uri
|
|
1916
|
-
val intent = android.content.Intent(
|
|
1917
|
-
activity,
|
|
1918
|
-
com.simba.player.PlayerActivity::class.java,
|
|
1919
|
-
).apply {
|
|
1920
|
-
putExtra(com.simba.player.PlayerActivity.EXTRA_URI, uri)
|
|
1921
|
-
putExtra(com.simba.player.PlayerActivity.EXTRA_TITLE, resolvedTitle)
|
|
1922
|
-
putExtra(com.simba.player.PlayerActivity.EXTRA_TYPE, type)
|
|
1923
|
-
putExtra(
|
|
1924
|
-
com.simba.player.PlayerActivity.EXTRA_START_POSITION_MS,
|
|
1925
|
-
startPositionMs.toLong(),
|
|
1926
|
-
)
|
|
1927
|
-
}
|
|
1928
|
-
// 3.6: launch + 3.7: catch the three documented failure modes
|
|
1929
|
-
// plus a generic catch-all. The order matters: ActivityNotFound
|
|
1930
|
-
// and SecurityException are subclasses of each other on some
|
|
1931
|
-
// OEMs, so we check the more specific one first.
|
|
1932
|
-
try {
|
|
1933
|
-
// Phase 13: cache the resolved launch params in the
|
|
1934
|
-
// companion so the JS layer inside the launched
|
|
1935
|
-
// PlayerActivity can read them back via
|
|
1936
|
-
// [getLaunchParams] on mount (the launched activity's
|
|
1937
|
-
// JS context is fresh — it doesn't have the
|
|
1938
|
-
// PlaybackContext state from MainActivity, so we
|
|
1939
|
-
// have to ship the params through the bridge).
|
|
1940
|
-
lastLaunchParams = LaunchParams(uri, resolvedTitle, type, startPositionMs.toLong())
|
|
1941
|
-
activity.startActivity(intent)
|
|
1942
|
-
Log.i(
|
|
1943
|
-
TAG,
|
|
1944
|
-
"[PlaybackTrace][Bridge][openPlayer] launched PlayerActivity uri='$uri' type='$type' startMs=${startPositionMs.toLong()}",
|
|
1945
|
-
)
|
|
1946
|
-
promise.resolve(true)
|
|
1947
|
-
} catch (e: android.content.ActivityNotFoundException) {
|
|
1948
|
-
Log.w(TAG, "[PlaybackTrace][Bridge][openPlayer] PlayerActivity not found: ${e.message}")
|
|
1949
|
-
emitErrorEvent("E_ACTIVITY_NOT_FOUND", "PlayerActivity is not declared in the manifest", e)
|
|
1950
|
-
promise.reject("E_ACTIVITY_NOT_FOUND", "PlayerActivity is not declared in the manifest", e)
|
|
1951
|
-
} catch (e: SecurityException) {
|
|
1952
|
-
Log.w(TAG, "[PlaybackTrace][Bridge][openPlayer] security refusal: ${e.message}")
|
|
1953
|
-
emitErrorEvent("E_SECURITY", "Manifest restriction refused PlayerActivity launch", e)
|
|
1954
|
-
promise.reject("E_SECURITY", "Manifest restriction refused PlayerActivity launch", e)
|
|
1955
|
-
} catch (e: Throwable) {
|
|
1956
|
-
Log.e(TAG, "[PlaybackTrace][Bridge][openPlayer] launch failed", e)
|
|
1957
|
-
emitErrorEvent("E_OPEN_PLAYER_FAILED", e.message ?: "openPlayer failed", e)
|
|
1958
|
-
promise.reject("E_OPEN_PLAYER_FAILED", e.message ?: "openPlayer failed", e)
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
1724
|
// ── Audio playback without an Activity (V20 Phase C) ────────────────────
|
|
1963
1725
|
// The primitive that makes the mini player possible.
|
|
1964
1726
|
//
|
|
@@ -2242,59 +2004,15 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2242
2004
|
}
|
|
2243
2005
|
}
|
|
2244
2006
|
|
|
2245
|
-
/**
|
|
2246
|
-
* Phase 13.3: one-shot accessor for the launch params the most
|
|
2247
|
-
* recent [openPlayer] call handed to `PlayerActivity`. PlayerActivity
|
|
2248
|
-
* (a fresh React context) calls this on mount so its JS can rebuild
|
|
2249
|
-
* a `PlaybackEntry` from the same intent extras that PlayerActivity's
|
|
2250
|
-
* own `by lazy {}` `launchUri` / `launchTitle` / `launchType` /
|
|
2251
|
-
* `launchStartPositionMs` properties read.
|
|
2252
|
-
*
|
|
2253
|
-
* Returns `null` when called from MainActivity (no recent
|
|
2254
|
-
* `openPlayer` invocation) — the App.tsx effect that calls this
|
|
2255
|
-
* is a no-op in that case, and the regular V11 inline-mount path
|
|
2256
|
-
* runs.
|
|
2257
|
-
*
|
|
2258
|
-
* One-shot semantics: the params are cleared after the first
|
|
2259
|
-
* read so a re-read in the same activity does not double-apply.
|
|
2260
|
-
* A second invocation from a different activity (e.g. an
|
|
2261
|
-
* expand-from-PiP path) would no-op on the cleared state, which
|
|
2262
|
-
* is correct — that path uses MainActivity's PlaybackContext, not
|
|
2263
|
-
* PlayerActivity's.
|
|
2264
|
-
*/
|
|
2265
|
-
@ReactMethod
|
|
2266
|
-
@Override
|
|
2267
|
-
override fun getLaunchParams(promise: Promise) {
|
|
2268
|
-
val params = lastLaunchParams
|
|
2269
|
-
if (params == null) {
|
|
2270
|
-
// No launch pending (or already consumed) — resolve with JS `null`
|
|
2271
|
-
// so the consumer's `await bridge.getLaunchParams()` sees the same
|
|
2272
|
-
// nullable shape the spec promised (`Promise<LaunchParams | null>`).
|
|
2273
|
-
promise.resolve(null)
|
|
2274
|
-
return
|
|
2275
|
-
}
|
|
2276
|
-
// Clear immediately — we want the next call (in the same
|
|
2277
|
-
// activity or any other) to see null. The first read is the
|
|
2278
|
-
// only meaningful one.
|
|
2279
|
-
lastLaunchParams = null
|
|
2280
|
-
val map = Arguments.createMap()
|
|
2281
|
-
map.putString("uri", params.uri)
|
|
2282
|
-
map.putString("title", params.title)
|
|
2283
|
-
map.putString("type", params.type)
|
|
2284
|
-
map.putDouble("startPositionMs", params.startPositionMs.toDouble())
|
|
2285
|
-
Log.i(TAG, "[PlaybackTrace][Bridge][getLaunchParams] returning uri='${params.uri}' type='${params.type}'")
|
|
2286
|
-
promise.resolve(map)
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
2007
|
// ── PlayerConfig (Phase 21) ──────────────────────────────────────────────
|
|
2290
2008
|
//
|
|
2291
2009
|
// Phase 21: `<PlayerProvider config={...}>` calls this with the
|
|
2292
2010
|
// JSON-serialised PlayerConfig. We parse + cache as a Kotlin Map
|
|
2293
|
-
// so
|
|
2294
|
-
//
|
|
2295
|
-
//
|
|
2296
|
-
//
|
|
2297
|
-
//
|
|
2011
|
+
// so individual keys can be read without re-parsing JSON.
|
|
2012
|
+
//
|
|
2013
|
+
// V21 F5: nothing reads that cache any more (its only reader,
|
|
2014
|
+
// `IMpvConfigProvider`, went with `PlayerActivity`). The setter
|
|
2015
|
+
// stays because `<PlayerProvider>` calls it on every mount.
|
|
2298
2016
|
//
|
|
2299
2017
|
// Idempotent: re-calling with the same JSON is safe (just
|
|
2300
2018
|
// overwrites the cache). The TS-side `PlayerProvider` only
|
|
@@ -2334,13 +2052,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2334
2052
|
}
|
|
2335
2053
|
}
|
|
2336
2054
|
|
|
2337
|
-
// IMpvConfigProvider (Phase 21): module-side accessor used by
|
|
2338
|
-
// PlayerActivity to read the active PlayerConfig without
|
|
2339
|
-
// crossing the Gradle boundary. Returns the Kotlin Map cached
|
|
2340
|
-
// by [setConfig], or null when no Provider has wrapped the
|
|
2341
|
-
// consumer app's root.
|
|
2342
|
-
override fun getCurrentConfig(): Map<String, Any?>? = currentConfig
|
|
2343
|
-
|
|
2344
2055
|
// ── Picture-in-Picture ─────────────────────────────────────────────────
|
|
2345
2056
|
|
|
2346
2057
|
/**
|