@simba-dev/react-native-media-player 1.13.8 → 1.15.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.
Files changed (27) hide show
  1. package/README.md +26 -24
  2. package/android/src/main/java/com/simba/player/MediaPlaybackService.kt +20 -17
  3. package/android/src/main/java/com/simba/player/PlayerPackage.kt +21 -6
  4. package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +18 -307
  5. package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +100 -0
  6. package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +116 -31
  7. package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -20
  8. package/package.json +2 -2
  9. package/src/bridge/MpvPlayerModule.ts +36 -83
  10. package/src/bridge/NativeMpvPlayer.ts +15 -52
  11. package/src/bridge/loadAndPlay.ts +65 -0
  12. package/src/components/PlayerRoot.tsx +9 -13
  13. package/src/components/SimbaVideo.tsx +121 -0
  14. package/src/components/__tests__/SimbaVideo.test.tsx +164 -0
  15. package/src/hooks/__tests__/useLaunchPlayback.test.tsx +44 -64
  16. package/src/hooks/useLaunchPlayback.ts +7 -11
  17. package/src/hooks/usePlayerActivity.ts +51 -60
  18. package/src/index.ts +11 -11
  19. package/src/specs/SimbaVideoViewNativeComponent.ts +84 -0
  20. package/src/types/__tests__/player.test.tsx +49 -17
  21. package/src/types/player.ts +28 -31
  22. package/android/src/main/java/com/simba/player/IMpvConfigProvider.kt +0 -36
  23. package/android/src/main/java/com/simba/player/IPipModeChangeEmitter.kt +0 -31
  24. package/android/src/main/java/com/simba/player/PlayerActivity.kt +0 -1626
  25. package/src/hooks/SimbaPlayerRoot.tsx +0 -128
  26. package/src/hooks/useIsPlayerActivity.ts +0 -61
  27. 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
- - **Dedicated `PlayerActivity`** — extends `ReactActivity`, mounts the mpv-powered `SurfaceView` at the content root (the proven pattern for stable PiP on Android). No more black-screen PiP bugs.
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
- Add the player to your `AndroidManifest.xml` (the package ships its own `<service>` and `<receiver>` declarations, but the **launchable activity** has to be registered in your app's manifest so the consumer can launch it):
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="com.simba.player.PlayerActivity"
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="false" />
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 — V15+ (one wrapper, one import, zero glue code)
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
- // <SimbaPlayerRoot> handles the activity-launch branch
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). `<SimbaPlayerRoot>` (V14) absorbs the `useLaunchParams()` + activity-branch switch. `useOpenFromUrl()` (V14) absorbs the deep-link URI-scheme filter + title-derivation + extension-classification. `getResumePosition` (V14) is the new function-prop shape for the resume lookup (replaces V13's `lookup={...}` object shape).
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
- // PlayerActivity launches, plays the file, supports PiP, etc.
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`. V14 adds the `getResumePosition` function prop (alongside the legacy `lookup` object prop). Use this at the app root. |
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), getLaunchParams() }` | ❌ No (no-op fallback) |
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`, `getLaunchParams`, `getProperty`, `setProperty`, `observeProperty`, `unobserveProperty`, `grantPersistablePermission`, `verifyContentUri` |
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 }` — read from the activity via `useLaunchParams()` |
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 listens via `PlayerActivity` registration and adjusts `mpv.setPropertyString('cache-secs', ...)`.
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 mirrors the existing `currentActivityIsPlayer` pattern used
151
- * elsewhere in this library.
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
- * Both this and the session-activity [PendingIntent] used to name
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 is about to delete, so
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 once playback lives
218
- * in a single Activity — so rather than assert a name and keep it in
219
- * sync, ask Android which component the launcher icon resolves to.
220
- * `CATEGORY_LAUNCHER` + `setPackage` is the platform's own answer to
221
- * "what does launching this app do", scoped to this package so it
222
- * cannot pick up another app's activity.
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 hostPlayerActivityIntent(context: Context): Intent? {
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
- * [hostPlayerActivityIntent] for why that degrades instead of
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 = hostPlayerActivityIntent(context) ?: return null
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
- // `hostPlayerActivityIntent`. `setSessionActivity(null)` is the
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
- hostPlayerActivityIntent(this@MediaPlaybackService)?.let { hostIntent ->
467
+ hostActivityIntent(this@MediaPlaybackService)?.let { hostIntent ->
465
468
  setSessionActivity(
466
469
  PendingIntent.getActivity(
467
470
  this@MediaPlaybackService,
@@ -5,7 +5,9 @@ import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.module.model.ReactModuleInfo
7
7
  import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import com.facebook.react.uimanager.ViewManager
8
9
  import com.simba.player.mpv.MpvBridgeModule
10
+ import com.simba.player.mpv.MpvRenderViewManager
9
11
 
10
12
  /**
11
13
  * React Native Package that registers the V12 player's native modules +
@@ -29,12 +31,13 @@ import com.simba.player.mpv.MpvBridgeModule
29
31
  * dependencies on `MPVLib` (also in the `mpv` subpackage). The new
30
32
  * `PlayerPackage` looks it up via its FQN.
31
33
  *
32
- * The `ViewManager` side is left empty — the module's `MpvRenderViewManager`
33
- * (which is V11-era and used only by the old `MainActivity` JS tree) is
34
- * kept in the `mpv` subpackage for backward compat until W8 (Phase 41+
35
- * deletes the V11 inline-mount path). PlayerActivity (Phase 6) mounts
36
- * `MpvRenderView` natively via `PlayerActivity.onCreate` so the JS-side
37
- * `<MpvRenderView />` component is no longer needed for V12 playback.
34
+ * Phase 6 note, superseded 2026-10-16: the ViewManager side is no longer
35
+ * empty. `MpvRenderViewManager` registers `SimbaVideoView`, so the mpv
36
+ * SurfaceView is an ordinary child of the React tree instead of being mounted
37
+ * by Kotlin at `android.R.id.content` index 0 as a sibling of the React root.
38
+ * That sibling arrangement is what let an opaque React root paint over every
39
+ * decoded frame. See `SimbaVideoViewManager` and
40
+ * `src/components/SimbaVideo.tsx`.
38
41
  */
39
42
  class PlayerPackage : TurboReactPackage() {
40
43
 
@@ -48,6 +51,18 @@ class PlayerPackage : TurboReactPackage() {
48
51
  }
49
52
  }
50
53
 
54
+ /**
55
+ * The video picture, as a real React Native view.
56
+ *
57
+ * Previously absent: the surface was mounted natively and `PlayerSurface`
58
+ * on the JS side was a no-op transparent `<View>` that only reserved layout
59
+ * space. A component with no native counterpart is what forced every screen
60
+ * to blank itself around the player.
61
+ */
62
+ override fun createViewManagers(
63
+ reactContext: ReactApplicationContext,
64
+ ): List<ViewManager<*, *>> = listOf(MpvRenderViewManager())
65
+
51
66
  override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
52
67
  return ReactModuleInfoProvider {
53
68
  mapOf(