@simba-dev/react-native-media-player 1.2.0 → 1.4.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 CHANGED
@@ -105,37 +105,153 @@ getMpvPlayerModule().requestNotificationPermission?.(); // graceful no-op on old
105
105
  ## Basic usage
106
106
 
107
107
  ```tsx
108
- // App.tsx
108
+ // App.tsx — V15+ (one wrapper, one import, zero glue code)
109
109
  import React from 'react';
110
- import { PlayerProvider, PlayerRoot } from '@simba-dev/react-native-media-player';
110
+ import {
111
+ SimbaPlayer,
112
+ SimbaPlayerRoot,
113
+ useOpenFromUrl,
114
+ } from '@simba-dev/react-native-media-player';
111
115
 
112
116
  export default function App() {
113
117
  return (
114
- <PlayerProvider>
115
- <PlayerRoot />
116
- </PlayerProvider>
118
+ <SimbaPlayer
119
+ getResumePosition={(uri) =>
120
+ store.getState().bookmarks.byFileUri[uri]?.positionMs
121
+ }
122
+ >
123
+ <AppContent />
124
+ </SimbaPlayer>
125
+ );
126
+ }
127
+
128
+ function AppContent() {
129
+ // Deep links: open incoming content:// + file:// URIs in the player.
130
+ const openFromUrl = useOpenFromUrl();
131
+ React.useEffect(() => {
132
+ Linking.getInitialURL().then(url => url && openFromUrl(url));
133
+ const sub = Linking.addEventListener('url', ({ url }) => openFromUrl(url));
134
+ return () => sub.remove();
135
+ }, [openFromUrl]);
136
+
137
+ // <SimbaPlayerRoot> handles the activity-launch branch
138
+ // (renders <PlayerRoot /> when launchParams is set, otherwise children).
139
+ return (
140
+ <SimbaPlayerRoot>
141
+ <YourNavigator />
142
+ </SimbaPlayerRoot>
117
143
  );
118
144
  }
119
145
  ```
120
146
 
121
- That's it — `<PlayerRoot>` renders `<PlayerSurface>` (the JS placeholder for the native SurfaceView) + `<DefaultControls>` (top bar + scrubber + transport buttons + auto-hide). Press play from the native side and the player comes alive.
147
+ 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).
122
148
 
123
- ### Launching a file from JS
149
+ ### Per-screen usage (V15+)
150
+
151
+ Every player-related call is a one-line module hook. No `useAppDispatch` in player files. No `useAppSelector(state => state.player.X)`. No V11-mirrored redux state.
124
152
 
125
153
  ```tsx
126
- import { NativeModules } from 'react-native';
154
+ import {
155
+ usePlayerActivity, // single-track play
156
+ useOpenPlaylist, // play all from a list
157
+ useQueue, // add / remove / reorder queue items
158
+ useSleepTimer, // arm a sleep timer
159
+ useEqualizer, // 10-band EQ
160
+ useIsLiked, // per-file "liked" state
161
+ useShuffle, // shuffle flag
162
+ } from '@simba-dev/react-native-media-player';
127
163
 
128
- const { MpvPlayerModule } = NativeModules;
164
+ // Single-track play (V14, unchanged)
165
+ const {openPlayer} = usePlayerActivity();
166
+ const handlePlay = (item) => openPlayer({uri: item.uri, title: item.title, type: 'audio'});
167
+
168
+ // Play all from a list (V15 — the "play all" two-step absorption)
169
+ const {openPlaylist} = useOpenPlaylist();
170
+ const handlePlayAll = () => openPlaylist(sortedTracks, {type: 'audio'});
171
+
172
+ // Add to queue (V15 — zustand-backed, no Redux)
173
+ const {addToQueue} = useQueue();
174
+ const handleAddToQueue = (item) => addToQueue({uri: item.uri, title: item.title, ...});
129
175
 
130
- await MpvPlayerModule.openPlayer(
131
- 'https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4',
132
- 'Big Buck Bunny',
133
- 'video', // or 'audio'
134
- 0, // start position in ms
135
- );
176
+ // Set sleep timer (V15 — public surface; the consumer hasn't wired UI yet)
177
+ const {endTime, setTimer, clear} = useSleepTimer();
178
+ const handleSet30Min = () => setTimer(30 * 60); // 30 minutes
179
+ ```
180
+
181
+ ### Launching a file from JS
182
+
183
+ ```tsx
184
+ import { usePlayerActivity } from '@simba-dev/react-native-media-player';
185
+
186
+ function TrackRow({ track }) {
187
+ const { openPlayer } = usePlayerActivity();
188
+ return (
189
+ <Pressable onPress={() => openPlayer({
190
+ uri: track.uri,
191
+ title: track.title,
192
+ type: 'audio', // 'video' | 'audio'
193
+ startPositionMs: 0, // optional
194
+ })}>
195
+ <Text>{track.title}</Text>
196
+ </Pressable>
197
+ );
198
+ }
136
199
  // PlayerActivity launches, plays the file, supports PiP, etc.
137
200
  ```
138
201
 
202
+ ### Resume-aware openPlayer (with bookmarks)
203
+
204
+ If your app has a bookmarks/history feature, wrap your tree in `<SimbaPlayer>` with a `lookup` adapter and use `useOpenWithResume()`. The hook accepts a `resumeId` and looks up the saved position via your adapter — no manual position plumbing in every call site.
205
+
206
+ ```tsx
207
+ // App.tsx
208
+ import { SimbaPlayer, type PlayerResumeLookup } from '@simba-dev/react-native-media-player';
209
+
210
+ const resumeLookup: PlayerResumeLookup = {
211
+ getResumePosition: (resumeId) => {
212
+ // resolve the resume position (ms) for the given item
213
+ // — return undefined for "no saved position"
214
+ return store.getState().bookmarks.byFileUri[resumeId]?.positionMs;
215
+ },
216
+ };
217
+
218
+ <SimbaPlayer lookup={resumeLookup}>
219
+ <AppContent />
220
+ </SimbaPlayer>
221
+
222
+ // TrackRow.tsx
223
+ import { useOpenWithResume } from '@simba-dev/react-native-media-player';
224
+
225
+ function TrackRow({ track }) {
226
+ const openPlayer = useOpenWithResume();
227
+ return (
228
+ <Pressable onPress={() => openPlayer({
229
+ uri: track.uri,
230
+ title: track.title,
231
+ type: 'audio',
232
+ resumeId: track.uri, // module looks up the saved position
233
+ })}>
234
+ <Text>{track.title}</Text>
235
+ </Pressable>
236
+ );
237
+ }
238
+ ```
239
+
240
+ ### Mapping content kinds to V13 stream types
241
+
242
+ If your items have content kinds like `'music'`, `'movie'`, `'podcast'` (not the V13 stream types `'audio' | 'video'`), use the `resolveStreamType` helper:
243
+
244
+ ```tsx
245
+ import { usePlayerActivity, resolveStreamType } from '@simba-dev/react-native-media-player';
246
+
247
+ const { openPlayer } = usePlayerActivity();
248
+ openPlayer({
249
+ uri: item.uri,
250
+ title: item.title,
251
+ type: resolveStreamType(item.kind), // 'music' -> 'audio', 'movie' -> 'video', etc.
252
+ });
253
+ ```
254
+
139
255
  ## Custom UI
140
256
 
141
257
  Two ways to swap the controls:
@@ -316,46 +432,59 @@ Default theme is dark with a golden accent (`DEFAULT_THEME`).
316
432
 
317
433
  ## API reference
318
434
 
319
- Every public export lives in [`src/index.ts`](./src/index.ts).
435
+ Every public export lives in [`src/index.ts`](./src/index.ts). The **V13+ surface** is the recommended way to integrate; the V12 surface (`PlayerProvider` + `usePlayer()` directly) still works for backward compatibility but is undocumented for new consumers.
320
436
 
321
- ### Components
437
+ ### Components (V13+ recommended, V14 additions in **bold**)
322
438
 
323
439
  | Component | Purpose |
324
440
  |---|---|
325
- | `<PlayerProvider>` | Wraps the app; provides resolved config + `renderControls` slot to descendants. |
326
- | `<PlayerRoot>` | Renders `<PlayerSurface>` + the controls overlay (custom via `renderControls` or `<DefaultControls>`). |
441
+ | `<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. |
442
+ | **`<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. |
443
+ | `<PlayerRoot>` | Renders `<PlayerSurface>` + the controls overlay (default `<DefaultControls>` or custom via `renderControls`). |
327
444
  | `<PlayerSurface>` | `<View flex:1>` placeholder for the native SurfaceView. a11y-hidden. |
328
445
  | `<DefaultControls>` | Pre-built controls (top bar, scrubber, transport, auto-hide). |
446
+ | `<PlayerProvider>` | (V12 surface) Wraps the app; provides resolved config + `renderControls` slot. Use `<SimbaPlayer>` instead unless you need the raw provider. |
329
447
 
330
- ### Hooks
448
+ ### Hooks (V13+, V14 additions in **bold**, V15 additions in __bold-italic__)
331
449
 
332
450
  | Hook | Returns | Throws outside provider? |
333
451
  |---|---|---|
452
+ | `usePlayerActivity()` | `{ openPlayer(opts), getLaunchParams() }` | ❌ No (no-op fallback) |
453
+ | `useOpenWithResume()` | `(opts: OpenPlayerOptions & { resumeId? }) => Promise<boolean>` | ❌ No (no-op lookup) |
454
+ | **`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 |
455
+ | **`useOpenPlaylist()`** | __V15 — `{ openPlaylist(entries, opts) }` — "play all from a list" two-step absorption. `opts: { type?, startIndex?, startPositionMs?, shuffle?, startExtras? }`__ | ❌ No |
456
+ | **`useSimbaPlayerLookup(selector?)`** | **`PlayerResumeLookup`** — **factory hook** that wraps an optional `selector` in a memoized lookup object. Without a selector, returns no-op. | ❌ No |
457
+ | __`useQueue()` / `useQueueItems()` / `useQueueLength()` / `usePlaybackHistory()`__ | __V15 — queue + playback history state (zustand-backed). `useQueue()` returns the full store (queue, history, 9 actions: addToQueue, prependToQueue, removeFromQueue, reorderQueue, clearQueue, shuffleQueue, playFromQueue, addToPlaybackHistory, clearPlaybackHistory).__ | ❌ No |
458
+ | __`useQueueSelection()` / `useQueueSelectedIndices()`__ | __V15 — multi-select state for the queue (selected indices + 4 actions: setSelection, clearSelection, removeSelected, moveSelectedToTop).__ | ❌ No |
459
+ | __`useSleepTimer()` / `useSleepTimerEnd()` / `useSleepTimerMode()`__ | __V15 — sleep timer state (endTime + mode) + actions (setTimer, setMode, clear).__ | ❌ No |
460
+ | __`useEqualizer()` / `useEqualizerEnabled()`__ | __V15 — 10-band equalizer (gains + enabled) + actions (setGains, toggle).__ | ❌ No |
461
+ | __`useIsLiked(uri)` / `useToggleLiked()`__ | __V15 — per-file "liked" state (Record<uri, boolean>) + toggle action.__ | ❌ No |
462
+ | __`useShuffle()` / `useShuffleEnabled()`__ | __V15 — shuffle flag + toggle action.__ | ❌ No |
463
+ | `usePlayItem()` | `(item, opts) => Promise<boolean>` | ❌ No (sugar on `useOpenWithResume`) |
464
+ | `useLaunchParams()` | `LaunchParams \| null` | ❌ No (returns null) |
465
+ | `usePlayer()` | `{ state: PlayerState, commands: PlayerCommands, progress: PlayerProgress }` | ❌ No (returns defaults) |
466
+ | `usePlayerProgress()` | `{ positionMs, durationMs, isBuffering, isSeeking, seekable, cacheRanges, cacheFill }` | ❌ No (returns 0/0) |
334
467
  | `usePlayerConfig()` | `ResolvedPlayerConfig` | ✅ Yes (programmer error) |
335
468
  | `useTheme()` | `PlayerTheme` | ✅ Yes (programmer error) |
336
469
  | `useRenderControls()` | `RenderControlsFn \| null` | ❌ No (falls back to default controls) |
337
- | `usePlayer()` | `{ state: PlayerState, commands: PlayerCommands }` | ❌ No (returns defaults) |
338
- | `usePlayerProgress()` | `{ positionMs: number, durationMs: number }` | ❌ No (returns 0/0) |
339
470
 
340
- ### Types
471
+ ### Types (V13+)
341
472
 
342
- | Type | Fields |
473
+ | Type | Notes |
343
474
  |---|---|
344
- | `PlayerConfig` | `theme?`, `pip?`, `audio?`, `subtitle?`, `notifications?`, `hardwareDecoding?`, `debug?` |
345
- | `ResolvedPlayerConfig` | Same as `PlayerConfig` but every field is required + defaulted |
346
- | `PlayerTheme` | `accent`, `background`, `text`, `textSecondary`, `surface`, `icon?` |
347
- | `PipConfig` | `enabled`, `autoEnterOnLeave` |
348
- | `AudioConfig` | `backgroundPlayback`, `respectAudioFocus` |
349
- | `SubtitleConfig` | `preferredLanguages`, `fontSize` |
350
- | `NotificationConfig` | `enabled`, `channelId` |
351
- | `DebugConfig` | `verboseLogging` |
352
- | `HardwareDecodingPolicy` | `'auto' \| 'mediacodec' \| 'no'` |
353
- | `PlayerState` | `isPlaying`, `title`, `artist`, `album` |
354
- | `PlayerProgress` | `positionMs`, `durationMs` |
355
- | `PlayerCommands` | `play()`, `pause()`, `seek(ms)`, `skipBackward(s)`, `skipForward(s)` |
356
- | `UsePlayerResult` | `{ state, commands }` |
357
- | `RenderControlsFn` | `() => React.ReactNode` |
358
- | `MpvPlayerModuleBridge` | Typed view of the native module |
475
+ | `PlayerState` | 20 fields: `isPlaying`, `title`, `artist`, `album`, `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `volume`, `isMuted`, `speed`, `loopMode`, `playlist`, `currentIndex`, `tracks`, `chapters`, `currentChapter`, `videoParams`, `error` |
476
+ | `PlayerProgress` | 7 fields: `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `cacheRanges`, `cacheFill` |
477
+ | `PlayerCommands` | 38 methods: `play`, `pause`, `seek`, `skipBackward`, `skipForward`, `togglePlayPause`, `stop`, `seekBy`, `seekToChapter`, `next`, `previous`, `setVolume`, `setMuted`, `toggleMute`, `setSpeed`, `setLoopMode`, `loadFile`, `loadPlaylist`, `playlistRemove`, `shuffle`, `clear`, `selectTrack`, `cycleTrack`, `setTrack`, `enterPip`, `exitPip`, `exitPipAndFinish`, `setKeepScreenOn`, `setOrientation`, `setImmersive`, `setScreenBrightness`, `requestNotificationPermission`, `openPlayer`, `getLaunchParams`, `getProperty`, `setProperty`, `observeProperty`, `unobserveProperty`, `grantPersistablePermission`, `verifyContentUri` |
478
+ | `OpenPlayerOptions` | `{ uri, title, type: 'video' \| 'audio', startPositionMs? }` — the V13 `openPlayer` arg shape (replaces V11's positional args) |
479
+ | `LaunchParams` | `{ uri, title, type, startPositionMs }` — read from the activity via `useLaunchParams()` |
480
+ | `ContentKind` | `'video' \| 'audio' \| 'music' \| 'movie' \| 'podcast' \| 'live-tv' \| 'radio' \| 'audiobook' \| 'archive-audio' \| 'episode' \| 'video-file' \| string` |
481
+ | `PlayerResumeLookup` | `{ getResumePosition(itemId: string): number \| undefined }` — adapter for the bookmark-aware resume lookup |
482
+ | **`GetResumePosition`** | **V14 — `(itemId: string) => number \| undefined`** — the function reference shape for `<SimbaPlayer getResumePosition={...}>` |
483
+ | `SimbaPlayerProps` | `{ config?, lookup?, getResumePosition?, children }` — V14 adds `getResumePosition` (function prop, recommended). If both `lookup` and `getResumePosition` are passed, `getResumePosition` wins. |
484
+ | **`SimbaPlayerRootProps`** | **V14 — `{ children: React.ReactNode }`** — the children are rendered when the activity was launched WITHOUT playback params |
485
+ | `MpvPlayerModuleBridge` | Typed view of the native module (78 methods) |
486
+ | `PlayerConfig`, `ResolvedPlayerConfig`, `PlayerTheme`, `PipConfig`, `AudioConfig`, `SubtitleConfig`, `NotificationConfig`, `DebugConfig`, `HardwareDecodingPolicy` | V12 surface — same as before |
487
+ | `MpvTrack`, `MpvChapter`, `MpvFileInfo`, `MpvVideoParams`, `MpvAudioDevice`, `MpvPlaybackState`, `MpvLoopMode`, `MpvEventName`, `MpvEvents`, `MpvEventPayloads`, `PlayerEventName`, `PlayerEventPayloads` | Low-level mpv types |
359
488
 
360
489
  ### Constants
361
490
 
@@ -370,6 +499,9 @@ Every public export lives in [`src/index.ts`](./src/index.ts).
370
499
  |---|---|
371
500
  | `resolvePlayerConfig(config)` | Merge a partial config with defaults — useful for tests / debug overlays |
372
501
  | `getMpvPlayerModule()` | Typed wrapper over `NativeModules.MpvPlayerModule`. Returns a no-op stub on non-RN platforms (jest, web). |
502
+ | `resolveStreamType(kind: ContentKind): 'video' \| 'audio'` | Map a content kind to the V13 stream type. Idempotent — `'video'` and `'audio'` pass through unchanged. Use this when your items have `'music'`, `'movie'`, etc. but V13 `openPlayer` expects `'video' | 'audio'`. |
503
+ | `subscribePlayerEvent(name, handler)` → unsubscribe | Subscribe to a native mpv event (22 events). Returns an unsubscribe function. |
504
+ | `removeAllListeners(event?)` | Remove all listeners for an event (or all events if no arg). |
373
505
 
374
506
  ## Troubleshooting
375
507
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.2.0",
4
- "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V13.0.0 stable release** (2026-09-04) — V13 extraction complete. See [`SIMBA_PLAYER_MODULE_V13_FINAL_QA_REPORT.md`](X:/Development/SIMBA/MOBILE_APP_REACT_NATIVE/md/SIMBA_PLAYER_MODULE_V13_FINAL_QA_REPORT.md) for the QA report. Published under the `@simba-dev` org (the bare `simba` org-name on npmjs was reserved at publication time).",
3
+ "version": "1.4.0",
4
+ "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V15.0.0 stable release** (2026-09-04) — per-screen simplification + state consolidation. Junior-dev surface across App.tsx AND per-screen code paths. See [`SIMBA_PLAYER_MODULE_V15_FINAL_QA_REPORT.md`](X:/Development/SIMBA/MOBILE_APP_REACT_NATIVE/md/SIMBA_PLAYER_MODULE_V15_FINAL_QA_REPORT.md) for the QA report. Published under the `@simba-dev` org (the bare `simba` org-name on npmjs was reserved at publication time).",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
7
7
  "react-native": "src/index.ts",
@@ -88,5 +88,8 @@
88
88
  },
89
89
  "bugs": {
90
90
  "url": "https://github.com/pavalep/react-native-media-player/issues"
91
+ },
92
+ "dependencies": {
93
+ "zustand": "^5.0.15"
91
94
  }
92
95
  }
@@ -1,8 +1,9 @@
1
- import React from 'react';
1
+ import React, {useMemo} from 'react';
2
2
  import { PlayerProvider } from '../components/PlayerProvider';
3
3
  import type { PlayerConfig } from '../types/config';
4
4
  import { PlayerResumeProvider } from './useOpenWithResume';
5
5
  import type { PlayerResumeLookup } from './useOpenWithResume';
6
+ import type { GetResumePosition } from './useSimbaPlayerLookup';
6
7
 
7
8
  /**
8
9
  * V13+ DX: the single-entry-point wrapper for the SIMBA player
@@ -25,11 +26,12 @@ import type { PlayerResumeLookup } from './useOpenWithResume';
25
26
  * import { SimbaPlayer } from '@simba-dev/react-native-media-player';
26
27
  *
27
28
  * export default function App() {
28
- * const playerLookup = useBookmarkLookup();
29
29
  * return (
30
30
  * <SimbaPlayer
31
31
  * config={{ theme: { accent: '#FFD700' } }}
32
- * lookup={playerLookup}
32
+ * getResumePosition={(uri) =>
33
+ * store.getState().bookmarks.byFileUri[uri]?.positionMs
34
+ * }
33
35
  * >
34
36
  * <RootNavigator />
35
37
  * </SimbaPlayer>
@@ -37,16 +39,26 @@ import type { PlayerResumeLookup } from './useOpenWithResume';
37
39
  * }
38
40
  * ```
39
41
  *
40
- * The `lookup` prop is optional — pass it to enable
41
- * `useOpenWithResume`'s auto-resume behavior. If you only need
42
- * `usePlayerActivity().openPlayer(...)` (no resume lookup), you
43
- * can omit `lookup` and the inner `<PlayerResumeProvider>` is
44
- * still mounted but with a no-op lookup that always returns 0.
42
+ * **V14 Phase 61:** the wrapper now accepts EITHER a
43
+ * `getResumePosition` function reference (recommended for new
44
+ * consumers) OR a `lookup` object (backward-compat for V13-era
45
+ * consumers). If both are passed, `getResumePosition` wins.
46
+ * The function-prop shape is one function reference instead of
47
+ * an object literal — slightly less typing, slightly less
48
+ * nesting.
49
+ *
50
+ * The `lookup` / `getResumePosition` props are optional — pass
51
+ * one to enable `useOpenWithResume`'s auto-resume behavior. If
52
+ * you only need `usePlayerActivity().openPlayer(...)` (no
53
+ * resume lookup), you can omit both and the inner
54
+ * `<PlayerResumeProvider>` is still mounted with a no-op lookup
55
+ * that always returns `undefined`.
45
56
  *
46
57
  * **Junior-dev rule of thumb:** if your screen calls
47
- * `openPlayer({resumeId: item.id})`, you need a `lookup` here.
48
- * If you only call `openPlayer({uri, title, type})` without
49
- * `resumeId`, the `lookup` is optional.
58
+ * `openPlayer({resumeId: item.id})`, you need a `lookup` or
59
+ * `getResumePosition` here. If you only call
60
+ * `openPlayer({uri, title, type})` without `resumeId`, the
61
+ * lookup is optional.
50
62
  */
51
63
  export interface SimbaPlayerProps {
52
64
  /**
@@ -55,13 +67,35 @@ export interface SimbaPlayerProps {
55
67
  */
56
68
  config?: PlayerConfig;
57
69
  /**
58
- * Bookmark-aware resume lookup. If provided, the module's
59
- * `useOpenWithResume` hook will resolve `resumeId` arguments
60
- * to a `startPositionMs` via this function. If omitted,
61
- * `useOpenWithResume` is a no-op for resume (every call starts
62
- * from 0).
70
+ * Bookmark-aware resume lookup (object shape). If provided,
71
+ * the module's `useOpenWithResume` hook will resolve
72
+ * `resumeId` arguments to a `startPositionMs` via this
73
+ * object's `getResumePosition` method.
74
+ *
75
+ * Backward-compat: V13-era consumers that pass a memoized
76
+ * `PlayerResumeLookup` object. New consumers should prefer
77
+ * the `getResumePosition` function-prop shape.
78
+ *
79
+ * If both `lookup` and `getResumePosition` are passed,
80
+ * `getResumePosition` wins.
63
81
  */
64
82
  lookup?: PlayerResumeLookup;
83
+ /**
84
+ * Bookmark-aware resume lookup (function shape). Receives a
85
+ * `resumeId` (typically a URI or item id) and returns the
86
+ * saved position in ms, or `undefined` for no saved position.
87
+ *
88
+ * **Recommended for new consumers.** One function reference
89
+ * instead of an object literal:
90
+ *
91
+ * ```tsx
92
+ * <SimbaPlayer getResumePosition={(uri) => store.getState().bookmarks.byFileUri[uri]?.positionMs}>
93
+ * ```
94
+ *
95
+ * If both `lookup` and `getResumePosition` are passed,
96
+ * `getResumePosition` wins.
97
+ */
98
+ getResumePosition?: GetResumePosition;
65
99
  children: React.ReactNode;
66
100
  }
67
101
 
@@ -72,11 +106,27 @@ export interface SimbaPlayerProps {
72
106
  export function SimbaPlayer({
73
107
  config,
74
108
  lookup,
109
+ getResumePosition,
75
110
  children,
76
111
  }: SimbaPlayerProps): React.ReactElement {
112
+ // `getResumePosition` wins over `lookup` if both are passed.
113
+ // Memoize the resulting lookup so the `PlayerResumeContext`
114
+ // value stays stable across renders — this is what keeps
115
+ // every `useOpenWithResume()` consumer from re-rendering on
116
+ // every root render.
117
+ const effectiveLookup = useMemo<PlayerResumeLookup>(() => {
118
+ if (getResumePosition) {
119
+ return {getResumePosition};
120
+ }
121
+ if (lookup) {
122
+ return lookup;
123
+ }
124
+ return noopLookup;
125
+ }, [getResumePosition, lookup]);
126
+
77
127
  return (
78
128
  <PlayerProvider config={config}>
79
- <PlayerResumeProvider lookup={lookup ?? noopLookup}>
129
+ <PlayerResumeProvider lookup={effectiveLookup}>
80
130
  {children}
81
131
  </PlayerResumeProvider>
82
132
  </PlayerProvider>
@@ -85,8 +135,9 @@ export function SimbaPlayer({
85
135
 
86
136
  /**
87
137
  * No-op lookup used when the consumer doesn't pass a `lookup`
88
- * prop. Always returns `undefined` so `useOpenWithResume` falls
89
- * back to 0 (or the consumer-provided `startPositionMs`).
138
+ * or `getResumePosition` prop. Always returns `undefined` so
139
+ * `useOpenWithResume` falls back to 0 (or the
140
+ * consumer-provided `startPositionMs`).
90
141
  */
91
142
  const noopLookup: PlayerResumeLookup = {
92
143
  getResumePosition: () => undefined,
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+ import { PlayerRoot } from '../components/PlayerRoot';
3
+ import { useLaunchParams } from './useLaunchParams';
4
+
5
+ /**
6
+ * V14 Phase 59: the activity-branch wrapper.
7
+ *
8
+ * The native `PlayerActivity` is launched with playback params
9
+ * (`{uri, title, type, startPositionMs}`) by any `openPlayer(...)` call.
10
+ * The activity's React tree should render the player surface +
11
+ * controls when those params are present, and the regular app
12
+ * navigator when they're not.
13
+ *
14
+ * Before V14, this branching lived in the consumer's `App.tsx`:
15
+ *
16
+ * ```tsx
17
+ * const launchParams = useLaunchParams();
18
+ * if (launchParams) {
19
+ * return <PlayerRoot />;
20
+ * }
21
+ * return <YourNavigator />;
22
+ * ```
23
+ *
24
+ * `<SimbaPlayerRoot>` absorbs both the hook call and the switch.
25
+ * Consumers just nest their navigator as children:
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * <SimbaPlayer getResumePosition={...}>
30
+ * <SimbaPlayerRoot>
31
+ * <YourNavigator />
32
+ * </SimbaPlayerRoot>
33
+ * </SimbaPlayer>
34
+ * ```
35
+ *
36
+ * The activity branch is opaque: the consumer cannot customize what
37
+ * is rendered when `launchParams` is non-null. The module owns the
38
+ * player surface + controls. If a consumer needs a different
39
+ * activity surface (rare), they should use `PlayerRoot` directly
40
+ * with `useLaunchParams()`.
41
+ *
42
+ * **Why this exists:** V14's junior-dev-level integration goal is
43
+ * that any consumer's `App.tsx` looks the same. The launch-params
44
+ * branch is the second-largest source of glue after the resume
45
+ * lookup and the deep-link handler — Phase 59 deletes it from the
46
+ * consumer's `App.tsx`.
47
+ */
48
+ export interface SimbaPlayerRootProps {
49
+ /**
50
+ * The regular app content (typically a navigator). Rendered when
51
+ * the activity was launched WITHOUT playback params — i.e., the
52
+ * user just opened the app from the launcher or the home screen
53
+ * icon, with no recent `openPlayer(...)` handoff queued.
54
+ */
55
+ children: React.ReactNode;
56
+ }
57
+
58
+ /**
59
+ * The activity-branch wrapper. Mounts `<PlayerRoot />` when the
60
+ * activity was launched with playback params, otherwise renders
61
+ * `children`. See `SimbaPlayerRootProps` for usage.
62
+ */
63
+ export function SimbaPlayerRoot({
64
+ children,
65
+ }: SimbaPlayerRootProps): React.ReactElement {
66
+ const launchParams = useLaunchParams();
67
+
68
+ if (launchParams) {
69
+ return <PlayerRoot />;
70
+ }
71
+
72
+ return <>{children}</>;
73
+ }