@simba-dev/react-native-media-player 1.0.8 → 1.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/README.md CHANGED
@@ -105,37 +105,121 @@ getMpvPlayerModule().requestNotificationPermission?.(); // graceful no-op on old
105
105
  ## Basic usage
106
106
 
107
107
  ```tsx
108
- // App.tsx
108
+ // App.tsx — V14+ (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
149
  ### Launching a file from JS
124
150
 
125
151
  ```tsx
126
- import { NativeModules } from 'react-native';
127
-
128
- const { MpvPlayerModule } = NativeModules;
152
+ import { usePlayerActivity } from '@simba-dev/react-native-media-player';
129
153
 
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
- );
154
+ function TrackRow({ track }) {
155
+ const { openPlayer } = usePlayerActivity();
156
+ return (
157
+ <Pressable onPress={() => openPlayer({
158
+ uri: track.uri,
159
+ title: track.title,
160
+ type: 'audio', // 'video' | 'audio'
161
+ startPositionMs: 0, // optional
162
+ })}>
163
+ <Text>{track.title}</Text>
164
+ </Pressable>
165
+ );
166
+ }
136
167
  // PlayerActivity launches, plays the file, supports PiP, etc.
137
168
  ```
138
169
 
170
+ ### Resume-aware openPlayer (with bookmarks)
171
+
172
+ 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.
173
+
174
+ ```tsx
175
+ // App.tsx
176
+ import { SimbaPlayer, type PlayerResumeLookup } from '@simba-dev/react-native-media-player';
177
+
178
+ const resumeLookup: PlayerResumeLookup = {
179
+ getResumePosition: (resumeId) => {
180
+ // resolve the resume position (ms) for the given item
181
+ // — return undefined for "no saved position"
182
+ return store.getState().bookmarks.byFileUri[resumeId]?.positionMs;
183
+ },
184
+ };
185
+
186
+ <SimbaPlayer lookup={resumeLookup}>
187
+ <AppContent />
188
+ </SimbaPlayer>
189
+
190
+ // TrackRow.tsx
191
+ import { useOpenWithResume } from '@simba-dev/react-native-media-player';
192
+
193
+ function TrackRow({ track }) {
194
+ const openPlayer = useOpenWithResume();
195
+ return (
196
+ <Pressable onPress={() => openPlayer({
197
+ uri: track.uri,
198
+ title: track.title,
199
+ type: 'audio',
200
+ resumeId: track.uri, // module looks up the saved position
201
+ })}>
202
+ <Text>{track.title}</Text>
203
+ </Pressable>
204
+ );
205
+ }
206
+ ```
207
+
208
+ ### Mapping content kinds to V13 stream types
209
+
210
+ If your items have content kinds like `'music'`, `'movie'`, `'podcast'` (not the V13 stream types `'audio' | 'video'`), use the `resolveStreamType` helper:
211
+
212
+ ```tsx
213
+ import { usePlayerActivity, resolveStreamType } from '@simba-dev/react-native-media-player';
214
+
215
+ const { openPlayer } = usePlayerActivity();
216
+ openPlayer({
217
+ uri: item.uri,
218
+ title: item.title,
219
+ type: resolveStreamType(item.kind), // 'music' -> 'audio', 'movie' -> 'video', etc.
220
+ });
221
+ ```
222
+
139
223
  ## Custom UI
140
224
 
141
225
  Two ways to swap the controls:
@@ -316,46 +400,52 @@ Default theme is dark with a golden accent (`DEFAULT_THEME`).
316
400
 
317
401
  ## API reference
318
402
 
319
- Every public export lives in [`src/index.ts`](./src/index.ts).
403
+ 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
404
 
321
- ### Components
405
+ ### Components (V13+ recommended, V14 additions in **bold**)
322
406
 
323
407
  | Component | Purpose |
324
408
  |---|---|
325
- | `<PlayerProvider>` | Wraps the app; provides resolved config + `renderControls` slot to descendants. |
326
- | `<PlayerRoot>` | Renders `<PlayerSurface>` + the controls overlay (custom via `renderControls` or `<DefaultControls>`). |
409
+ | `<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. |
410
+ | **`<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. |
411
+ | `<PlayerRoot>` | Renders `<PlayerSurface>` + the controls overlay (default `<DefaultControls>` or custom via `renderControls`). |
327
412
  | `<PlayerSurface>` | `<View flex:1>` placeholder for the native SurfaceView. a11y-hidden. |
328
413
  | `<DefaultControls>` | Pre-built controls (top bar, scrubber, transport, auto-hide). |
414
+ | `<PlayerProvider>` | (V12 surface) Wraps the app; provides resolved config + `renderControls` slot. Use `<SimbaPlayer>` instead unless you need the raw provider. |
329
415
 
330
- ### Hooks
416
+ ### Hooks (V13+, V14 additions in **bold**)
331
417
 
332
418
  | Hook | Returns | Throws outside provider? |
333
419
  |---|---|---|
420
+ | `usePlayerActivity()` | `{ openPlayer(opts), getLaunchParams() }` | ❌ No (no-op fallback) |
421
+ | `useOpenWithResume()` | `(opts: OpenPlayerOptions & { resumeId? }) => Promise<boolean>` | ❌ No (no-op lookup) |
422
+ | **`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 |
423
+ | **`useSimbaPlayerLookup(selector?)`** | **`PlayerResumeLookup`** — **factory hook** that wraps an optional `selector` in a memoized lookup object. Without a selector, returns no-op. | ❌ No |
424
+ | `usePlayItem()` | `(item, opts) => Promise<boolean>` | ❌ No (sugar on `useOpenWithResume`) |
425
+ | `useLaunchParams()` | `LaunchParams \| null` | ❌ No (returns null) |
426
+ | `usePlayer()` | `{ state: PlayerState, commands: PlayerCommands, progress: PlayerProgress }` | ❌ No (returns defaults) |
427
+ | `usePlayerProgress()` | `{ positionMs, durationMs, isBuffering, isSeeking, seekable, cacheRanges, cacheFill }` | ❌ No (returns 0/0) |
334
428
  | `usePlayerConfig()` | `ResolvedPlayerConfig` | ✅ Yes (programmer error) |
335
429
  | `useTheme()` | `PlayerTheme` | ✅ Yes (programmer error) |
336
430
  | `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
431
 
340
- ### Types
432
+ ### Types (V13+)
341
433
 
342
- | Type | Fields |
434
+ | Type | Notes |
343
435
  |---|---|
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 |
436
+ | `PlayerState` | 20 fields: `isPlaying`, `title`, `artist`, `album`, `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `volume`, `isMuted`, `speed`, `loopMode`, `playlist`, `currentIndex`, `tracks`, `chapters`, `currentChapter`, `videoParams`, `error` |
437
+ | `PlayerProgress` | 7 fields: `positionMs`, `durationMs`, `isBuffering`, `isSeeking`, `seekable`, `cacheRanges`, `cacheFill` |
438
+ | `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` |
439
+ | `OpenPlayerOptions` | `{ uri, title, type: 'video' \| 'audio', startPositionMs? }` — the V13 `openPlayer` arg shape (replaces V11's positional args) |
440
+ | `LaunchParams` | `{ uri, title, type, startPositionMs }` — read from the activity via `useLaunchParams()` |
441
+ | `ContentKind` | `'video' \| 'audio' \| 'music' \| 'movie' \| 'podcast' \| 'live-tv' \| 'radio' \| 'audiobook' \| 'archive-audio' \| 'episode' \| 'video-file' \| string` |
442
+ | `PlayerResumeLookup` | `{ getResumePosition(itemId: string): number \| undefined }` — adapter for the bookmark-aware resume lookup |
443
+ | **`GetResumePosition`** | **V14 — `(itemId: string) => number \| undefined`** — the function reference shape for `<SimbaPlayer getResumePosition={...}>` |
444
+ | `SimbaPlayerProps` | `{ config?, lookup?, getResumePosition?, children }` — V14 adds `getResumePosition` (function prop, recommended). If both `lookup` and `getResumePosition` are passed, `getResumePosition` wins. |
445
+ | **`SimbaPlayerRootProps`** | **V14 — `{ children: React.ReactNode }`** — the children are rendered when the activity was launched WITHOUT playback params |
446
+ | `MpvPlayerModuleBridge` | Typed view of the native module (78 methods) |
447
+ | `PlayerConfig`, `ResolvedPlayerConfig`, `PlayerTheme`, `PipConfig`, `AudioConfig`, `SubtitleConfig`, `NotificationConfig`, `DebugConfig`, `HardwareDecodingPolicy` | V12 surface — same as before |
448
+ | `MpvTrack`, `MpvChapter`, `MpvFileInfo`, `MpvVideoParams`, `MpvAudioDevice`, `MpvPlaybackState`, `MpvLoopMode`, `MpvEventName`, `MpvEvents`, `MpvEventPayloads`, `PlayerEventName`, `PlayerEventPayloads` | Low-level mpv types |
359
449
 
360
450
  ### Constants
361
451
 
@@ -370,6 +460,9 @@ Every public export lives in [`src/index.ts`](./src/index.ts).
370
460
  |---|---|
371
461
  | `resolvePlayerConfig(config)` | Merge a partial config with defaults — useful for tests / debug overlays |
372
462
  | `getMpvPlayerModule()` | Typed wrapper over `NativeModules.MpvPlayerModule`. Returns a no-op stub on non-RN platforms (jest, web). |
463
+ | `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'`. |
464
+ | `subscribePlayerEvent(name, handler)` → unsubscribe | Subscribe to a native mpv event (22 events). Returns an unsubscribe function. |
465
+ | `removeAllListeners(event?)` | Remove all listeners for an event (or all events if no arg). |
373
466
 
374
467
  ## Troubleshooting
375
468
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.0.8",
4
- "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V12.0.0 stable release** (2026-09-03) — see [`SIMBA_PLAYER_MODULE_V12_RELEASE_RUNBOOK.md`](file:///x:/Development/SIMBA/MOBILE_APP_REACT_NATIVE/md/SIMBA_PLAYER_MODULE_V12_RELEASE_RUNBOOK.md) for the tag + APK + NPM procedures. Published under the `@simba-dev` org (the bare `simba` org-name on npmjs was reserved at publication time).",
3
+ "version": "1.3.0",
4
+ "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V14.0.0 stable release** (2026-09-04) — junior-dev-level integration surface. See [`SIMBA_PLAYER_MODULE_V14_FINAL_QA_REPORT.md`](X:/Development/SIMBA/MOBILE_APP_REACT_NATIVE/md/SIMBA_PLAYER_MODULE_V14_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",