@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 +132 -39
- package/package.json +2 -2
- package/src/bridge/MpvPlayerModule.ts +652 -70
- package/src/bridge/__tests__/errorContract.test.ts +10 -6
- package/src/components/PlayerProvider.tsx +288 -7
- package/src/hooks/SimbaPlayer.tsx +144 -0
- package/src/hooks/SimbaPlayerRoot.tsx +73 -0
- package/src/hooks/useLaunchParams.tsx +64 -0
- package/src/hooks/useOpenFromUrl.tsx +174 -0
- package/src/hooks/useOpenWithResume.tsx +236 -0
- package/src/hooks/usePlayerActivity.ts +103 -0
- package/src/hooks/useSimbaPlayerLookup.tsx +58 -0
- package/src/index.ts +38 -0
- package/src/types/__tests__/player.test.tsx +494 -0
- package/src/types/player.ts +947 -72
- package/src/types/__tests__/player.test.ts +0 -166
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
1
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Phase 39 debug-mode flag. `__DEV__` is set by React Native (true for
|
|
@@ -28,98 +28,598 @@ function dlog(...args: unknown[]): void {
|
|
|
28
28
|
console.log('[SimbaPlayer]', ...args);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
32
|
+
// Event types (V13 Phase 50c)
|
|
33
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
34
|
+
|
|
35
|
+
/** Playback state values emitted on `onPlaybackStateChanged`. */
|
|
36
|
+
export type MpvPlaybackState = 'idle' | 'playing' | 'paused' | 'stopped' | 'error';
|
|
37
|
+
|
|
38
|
+
/** Loop mode values used by `setLoopMode` / `getLoopMode`. */
|
|
39
|
+
export type MpvLoopMode = 'none' | 'file' | 'playlist';
|
|
40
|
+
|
|
41
|
+
/** mpv track metadata. */
|
|
42
|
+
export interface MpvTrack {
|
|
43
|
+
readonly id: number;
|
|
44
|
+
readonly type: 'video' | 'audio' | 'sub';
|
|
45
|
+
readonly title?: string;
|
|
46
|
+
readonly lang?: string;
|
|
47
|
+
readonly default: boolean;
|
|
48
|
+
readonly selected: boolean;
|
|
49
|
+
readonly codec?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** mpv chapter metadata. */
|
|
53
|
+
export interface MpvChapter {
|
|
54
|
+
readonly id: number;
|
|
55
|
+
readonly title: string;
|
|
56
|
+
readonly startTime: number;
|
|
57
|
+
readonly endTime: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** mpv file info (from `getFileInfo`). */
|
|
61
|
+
export interface MpvFileInfo {
|
|
62
|
+
readonly path: string;
|
|
63
|
+
readonly title: string;
|
|
64
|
+
readonly duration: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** mpv video params (from `getVideoParams`). */
|
|
68
|
+
export interface MpvVideoParams {
|
|
69
|
+
readonly videoWidth: number;
|
|
70
|
+
readonly videoHeight: number;
|
|
71
|
+
readonly aspectRatio: number;
|
|
72
|
+
readonly fps: number;
|
|
73
|
+
readonly codec: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** mpv audio device. */
|
|
77
|
+
export interface MpvAudioDevice {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly description: string;
|
|
80
|
+
readonly isDefault: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Launch params shared with `PlayerActivity` via `getLaunchParams`. */
|
|
84
|
+
export interface LaunchParams {
|
|
85
|
+
readonly uri: string;
|
|
86
|
+
readonly title: string;
|
|
87
|
+
readonly type: 'video' | 'audio';
|
|
88
|
+
readonly startPositionMs: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** All 22 events emitted by the Kotlin bridge. */
|
|
92
|
+
export type PlayerEventName =
|
|
93
|
+
| 'onFileLoaded'
|
|
94
|
+
| 'onPlaybackStateChanged'
|
|
95
|
+
| 'onPositionChanged'
|
|
96
|
+
| 'onDurationChanged'
|
|
97
|
+
| 'onPropertyChanged'
|
|
98
|
+
| 'onTracksChanged'
|
|
99
|
+
| 'onChapterChanged'
|
|
100
|
+
| 'onVideoParamsChanged'
|
|
101
|
+
| 'onError'
|
|
102
|
+
| 'onBuffering'
|
|
103
|
+
| 'onCacheState'
|
|
104
|
+
| 'onSeekable'
|
|
105
|
+
| 'onSeeking'
|
|
106
|
+
| 'onEndFile'
|
|
107
|
+
| 'onPlaybackRestart'
|
|
108
|
+
| 'onEndReached'
|
|
109
|
+
| 'onAudioDeviceChanged'
|
|
110
|
+
| 'onVolumeChanged'
|
|
111
|
+
| 'onSpeedChanged'
|
|
112
|
+
| 'videoReconfig'
|
|
113
|
+
| 'onPipModeChanged'
|
|
114
|
+
| 'onPipPlayPause'
|
|
115
|
+
| 'onPipExpand'
|
|
116
|
+
| 'onPipClose';
|
|
117
|
+
|
|
118
|
+
/** Typed payload map for each event. */
|
|
119
|
+
export interface PlayerEventPayloads {
|
|
120
|
+
onFileLoaded: { requestId?: string; resolvedPath?: string; file?: MpvFileInfo };
|
|
121
|
+
onPlaybackStateChanged: { state: MpvPlaybackState };
|
|
122
|
+
onPositionChanged: { position: number };
|
|
123
|
+
onDurationChanged: { duration: number };
|
|
124
|
+
onPropertyChanged: { property: string; value: unknown };
|
|
125
|
+
onTracksChanged: { tracks: MpvTrack[] };
|
|
126
|
+
onChapterChanged: { chapter: MpvChapter | null };
|
|
127
|
+
onVideoParamsChanged: { params: MpvVideoParams };
|
|
128
|
+
onError: { code: number; recoverable: boolean; message: string; requestId?: string };
|
|
129
|
+
onBuffering: { percent: number; isBuffering?: boolean };
|
|
130
|
+
onCacheState: { ranges: Array<{ start: number; end: number }>; fill: number };
|
|
131
|
+
onSeekable: { seekable: boolean };
|
|
132
|
+
onSeeking: { seeking: boolean };
|
|
133
|
+
onEndFile: { reason: number; error: number; requestId?: string };
|
|
134
|
+
onPlaybackRestart: Record<string, never>;
|
|
135
|
+
onEndReached: Record<string, never>;
|
|
136
|
+
onAudioDeviceChanged: { device: string };
|
|
137
|
+
onVolumeChanged: { volume: number };
|
|
138
|
+
onSpeedChanged: { speed: number };
|
|
139
|
+
videoReconfig: Record<string, never>;
|
|
140
|
+
onPipModeChanged: { isInPip: boolean };
|
|
141
|
+
onPipPlayPause: Record<string, never>;
|
|
142
|
+
onPipExpand: Record<string, never>;
|
|
143
|
+
onPipClose: Record<string, never>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
147
|
+
// Bridge surface (V13 Phase 50a — 78 methods)
|
|
148
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
149
|
+
|
|
31
150
|
/**
|
|
32
151
|
* Typed shape of the `MpvPlayerModule` native bridge as exposed by
|
|
33
|
-
* `MpvBridgeModule.kt
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
152
|
+
* `MpvBridgeModule.kt`. V13 Phase 50 expands the Phase 24 entry point
|
|
153
|
+
* (9 methods) to the full 78-method surface so consumers never need to
|
|
154
|
+
* reach into `NativeModules.MpvPlayerModule` directly.
|
|
155
|
+
*
|
|
156
|
+
* Method categories follow the Kotlin declaration order:
|
|
157
|
+
* - Lifecycle (init/destroy/getNativePtr)
|
|
158
|
+
* - Playback control (play/pause/seek/etc.)
|
|
159
|
+
* - File loading (loadFile/loadPlaylist/grantPermission/verifyUri)
|
|
160
|
+
* - Tracks + chapters
|
|
161
|
+
* - Volume + audio
|
|
162
|
+
* - Speed + loop
|
|
163
|
+
* - Property observe + get/set
|
|
164
|
+
* - Filters + playlist
|
|
165
|
+
* - State queries
|
|
166
|
+
* - Activity launch (openPlayer/getLaunchParams)
|
|
167
|
+
* - Configuration (setConfig)
|
|
168
|
+
* - PiP + screen
|
|
169
|
+
* - Orientation + immersive
|
|
170
|
+
* - Brightness
|
|
171
|
+
* - Notification
|
|
172
|
+
* - Debug
|
|
38
173
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* guarding every call site.
|
|
47
|
-
* - Typed return values let us add per-call error handling in a
|
|
48
|
-
* single place when we upgrade from "best-effort fire-and-forget"
|
|
49
|
-
* to "track success / failure".
|
|
174
|
+
* Event subscription (`subscribePlayerEvent` / `removeAllListeners`)
|
|
175
|
+
* is NOT a method on this bridge because the native module doesn't
|
|
176
|
+
* expose those names directly — it has `addListener` /
|
|
177
|
+
* `removeListeners` (required by React Native's `NativeEventEmitter`)
|
|
178
|
+
* and the events are emitted via `RCTDeviceEventEmitter`. The module
|
|
179
|
+
* wraps the emitter + adds typed event payloads; see the free
|
|
180
|
+
* functions below.
|
|
50
181
|
*/
|
|
51
182
|
export interface MpvPlayerModuleBridge {
|
|
52
|
-
|
|
183
|
+
// ── Lifecycle ──────────────────────────────────────────────────────────
|
|
184
|
+
/** Initialize the mpv engine. Idempotent. Returns true on success. */
|
|
185
|
+
initPlayer(): boolean;
|
|
186
|
+
/** Tear down the mpv engine. */
|
|
187
|
+
destroy(): void;
|
|
188
|
+
/** Native pointer to the active mpv instance (used by `MpvRenderView`). */
|
|
189
|
+
getNativePtr(): number;
|
|
190
|
+
|
|
191
|
+
// ── Playback control ───────────────────────────────────────────────────
|
|
192
|
+
/** Resume playback. */
|
|
53
193
|
play(): void;
|
|
54
|
-
/** Pause playback (mpv
|
|
194
|
+
/** Pause playback (mpv retains current position). */
|
|
55
195
|
pause(): void;
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
196
|
+
/** Stop playback entirely. */
|
|
197
|
+
stop(): void;
|
|
198
|
+
/** Toggle between play and pause. */
|
|
199
|
+
togglePlayPause(): void;
|
|
200
|
+
/** Seek to an absolute position in seconds. */
|
|
61
201
|
seekAbsolute(positionSeconds: number): void;
|
|
62
|
-
/** Skip
|
|
63
|
-
seekBackward(seconds: number): void;
|
|
64
|
-
/** Skip forward by N seconds. */
|
|
202
|
+
/** Skip forward N seconds. */
|
|
65
203
|
seekForward(seconds: number): void;
|
|
66
|
-
/**
|
|
67
|
-
|
|
204
|
+
/** Skip backward N seconds. */
|
|
205
|
+
seekBackward(seconds: number): void;
|
|
206
|
+
/** Step one frame; direction 1 = forward, -1 = backward. */
|
|
207
|
+
stepFrame(direction: 1 | -1): void;
|
|
208
|
+
/** Capture a screenshot; returns the file path. */
|
|
209
|
+
screenshot(): string;
|
|
210
|
+
|
|
211
|
+
// ── File loading ───────────────────────────────────────────────────────
|
|
212
|
+
/** Load a media file by path / URI. */
|
|
213
|
+
loadFile(path: string): void;
|
|
214
|
+
/** Load a media file with an attached request ID for traceability. */
|
|
215
|
+
loadFileWithRequestId(path: string, requestId: string): void;
|
|
216
|
+
/** Load a playlist of paths, starting at `startIndex` (default 0). */
|
|
217
|
+
loadPlaylist(paths: string[], startIndex?: number): void;
|
|
218
|
+
/** Get the currently-loaded file info as a JSON string. */
|
|
219
|
+
getFileInfo(): string;
|
|
220
|
+
/** Get the currently-loaded video params as a JSON string. */
|
|
221
|
+
getVideoParams(): string;
|
|
222
|
+
/** Capture a thumbnail screenshot for the given URI; returns the file path. */
|
|
223
|
+
captureThumbnail(uri: string): string;
|
|
224
|
+
/** Take a persistable read URI permission for a content:// URI. */
|
|
225
|
+
grantPersistablePermission(uri: string): void;
|
|
226
|
+
/** Returns true when the URI is still readable (content:// or file://). */
|
|
227
|
+
verifyContentUri(uri: string): boolean;
|
|
228
|
+
|
|
229
|
+
// ── Tracks ─────────────────────────────────────────────────────────────
|
|
230
|
+
/** Get the mpv track list as a JSON string. */
|
|
231
|
+
getTracks(): string;
|
|
232
|
+
/** Select the track by ID. */
|
|
233
|
+
selectTrack(trackId: number): void;
|
|
234
|
+
/** Cycle to the next/previous track of the given type. */
|
|
235
|
+
cycleTrack(type: 'video' | 'audio' | 'sub'): void;
|
|
236
|
+
/** Set the active track for a type (trackId < 0 means "no"). */
|
|
237
|
+
setTrack(type: 'video' | 'audio' | 'sub', trackId: number): void;
|
|
238
|
+
/** No-op; mpv manages visibility automatically. */
|
|
239
|
+
setTrackVisibility(trackType: string, visible: boolean): void;
|
|
240
|
+
|
|
241
|
+
// ── Chapters ───────────────────────────────────────────────────────────
|
|
242
|
+
/** Get the chapter list as a JSON string. */
|
|
243
|
+
getChapters(): string;
|
|
244
|
+
/** Seek to the next (1) or previous (-1) chapter. */
|
|
245
|
+
seekChapter(direction: 1 | -1): void;
|
|
246
|
+
/** Get the current chapter as a JSON string. */
|
|
247
|
+
getCurrentChapter(): string;
|
|
248
|
+
|
|
249
|
+
// ── Volume / audio ─────────────────────────────────────────────────────
|
|
250
|
+
/** Set the playback volume (0..100). */
|
|
251
|
+
setVolume(volume: number): void;
|
|
252
|
+
/** Get the current playback volume. */
|
|
253
|
+
getVolume(): number;
|
|
254
|
+
/** Set the muted state. */
|
|
255
|
+
setMuted(muted: boolean): void;
|
|
256
|
+
/** Get the muted state. */
|
|
257
|
+
getMuted(): boolean;
|
|
258
|
+
/** Alias for `getMuted`. */
|
|
259
|
+
isMuted(): boolean;
|
|
260
|
+
/** Get the list of mpv audio devices as a JSON string. */
|
|
261
|
+
getAudioDevices(): string;
|
|
262
|
+
/** Switch to the given mpv audio device. */
|
|
263
|
+
setAudioDevice(deviceName: string): void;
|
|
264
|
+
/** Toggle the muted state. */
|
|
265
|
+
toggleMute(): void;
|
|
266
|
+
|
|
267
|
+
// ── Playback speed ─────────────────────────────────────────────────────
|
|
268
|
+
/** Set the playback speed (1.0 = normal). */
|
|
269
|
+
setSpeed(speed: number): void;
|
|
270
|
+
/** Get the current playback speed. */
|
|
271
|
+
getSpeed(): number;
|
|
272
|
+
|
|
273
|
+
// ── Loop / repeat ──────────────────────────────────────────────────────
|
|
274
|
+
/** Set the loop mode (`'none' | 'file' | 'playlist'`). */
|
|
275
|
+
setLoopMode(mode: MpvLoopMode): void;
|
|
276
|
+
/** Get the current loop mode. */
|
|
277
|
+
getLoopMode(): MpvLoopMode;
|
|
278
|
+
/** Toggle playlist loop on/off. */
|
|
279
|
+
setPlaylistLoop(loop: boolean): void;
|
|
280
|
+
|
|
281
|
+
// ── Properties (generic get/set for any mpv property) ─────────────────
|
|
282
|
+
/** Get the value of an mpv property as a string. */
|
|
283
|
+
getProperty(name: string): string;
|
|
284
|
+
/** Set the value of an mpv property. Value is stringified before sending. */
|
|
285
|
+
setProperty(name: string, value: unknown): void;
|
|
286
|
+
/** Begin observing an mpv property (emits `onPropertyChanged` events). */
|
|
287
|
+
observeProperty(name: string): void;
|
|
288
|
+
/** Stop observing an mpv property. */
|
|
289
|
+
unobserveProperty(name: string): void;
|
|
290
|
+
|
|
291
|
+
// ── Video / audio filters ──────────────────────────────────────────────
|
|
292
|
+
/** Toggle a video filter (`filter` is an mpv `vf` string). */
|
|
293
|
+
setVideoFilter(filter: string, enabled: boolean): void;
|
|
294
|
+
/** Toggle an audio filter (`filter` is an mpv `af` string). */
|
|
295
|
+
setAudioFilter(filter: string, enabled: boolean): void;
|
|
296
|
+
|
|
297
|
+
// ── Playlist ───────────────────────────────────────────────────────────
|
|
298
|
+
/** Get the current playlist as a JSON string. */
|
|
299
|
+
getPlaylist(): string;
|
|
300
|
+
/** Skip to the next entry in the playlist. */
|
|
301
|
+
playlistNext(): void;
|
|
302
|
+
/** Skip to the previous entry in the playlist. */
|
|
303
|
+
playlistPrev(): void;
|
|
304
|
+
/** Remove the entry at `index` from the playlist. */
|
|
305
|
+
playlistRemove(index: number): void;
|
|
306
|
+
/** Shuffle the current playlist. */
|
|
307
|
+
playlistShuffle(): void;
|
|
308
|
+
/** Clear the current playlist. */
|
|
309
|
+
playlistClear(): void;
|
|
310
|
+
|
|
311
|
+
// ── State queries ──────────────────────────────────────────────────────
|
|
312
|
+
/** Get the current playback position in seconds. */
|
|
313
|
+
getPosition(): number;
|
|
314
|
+
/** Get the duration of the current file in seconds. */
|
|
315
|
+
getDuration(): number;
|
|
316
|
+
/** Get the current playback state. */
|
|
317
|
+
getPlaybackState(): MpvPlaybackState;
|
|
318
|
+
|
|
319
|
+
// ── Activity launch (V12 Phase 3 / V13 Phase 52) ───────────────────────
|
|
68
320
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* Default: false. Use during development / debugging.
|
|
321
|
+
* Hand off to the dedicated `PlayerActivity`. Returns true on
|
|
322
|
+
* successful `startActivity`. Rejects with `E_INVALID_TYPE`,
|
|
323
|
+
* `E_NO_ACTIVITY`, `E_ACTIVITY_NOT_FOUND`, `E_SECURITY`, or
|
|
324
|
+
* `E_OPEN_PLAYER_FAILED`.
|
|
74
325
|
*/
|
|
75
|
-
|
|
326
|
+
openPlayer(
|
|
327
|
+
uri: string,
|
|
328
|
+
title: string | null,
|
|
329
|
+
type: 'video' | 'audio',
|
|
330
|
+
startPositionMs: number,
|
|
331
|
+
): Promise<boolean>;
|
|
332
|
+
/**
|
|
333
|
+
* One-shot accessor for the launch params the most recent
|
|
334
|
+
* `openPlayer` call handed to `PlayerActivity`. Returns `null`
|
|
335
|
+
* when called from MainActivity or after the first read has
|
|
336
|
+
* already consumed the value.
|
|
337
|
+
*/
|
|
338
|
+
getLaunchParams(): LaunchParams | null;
|
|
339
|
+
|
|
340
|
+
// ── Configuration (V12 Phase 21) ───────────────────────────────────────
|
|
76
341
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* the property count (for test verification).
|
|
342
|
+
* Push the latest PlayerConfig JSON to the native side. Resolves
|
|
343
|
+
* with the count of top-level keys parsed.
|
|
80
344
|
*/
|
|
345
|
+
setConfig(configJson: string): Promise<number>;
|
|
346
|
+
|
|
347
|
+
// ── Picture-in-Picture ─────────────────────────────────────────────────
|
|
348
|
+
/** Enter PiP mode; optional chapter title + progress percent for notification. */
|
|
349
|
+
enterPip(chapterTitle?: string, progressPct?: string): void;
|
|
350
|
+
/** Exit PiP by bringing the activity to the front. */
|
|
351
|
+
exitPip(): void;
|
|
352
|
+
/** Exit PiP and finish the activity. */
|
|
353
|
+
exitPipAndFinish(): void;
|
|
354
|
+
|
|
355
|
+
// ── Keep screen on (V12 W2.12) ──────────────────────────────────────────
|
|
356
|
+
/** Toggle `FLAG_KEEP_SCREEN_ON` on the current activity window. */
|
|
357
|
+
setKeepScreenOn(enabled: boolean): void;
|
|
358
|
+
|
|
359
|
+
// ── Orientation / immersive (v11 T8.1) ─────────────────────────────────
|
|
360
|
+
/**
|
|
361
|
+
* Pin the activity to a fixed orientation. `'portrait'`,
|
|
362
|
+
* `'landscape'`, or `'sensor'` for free rotation. Feature-detected
|
|
363
|
+
* by the consumer (older builds omit this).
|
|
364
|
+
*/
|
|
365
|
+
setOrientation(mode: 'portrait' | 'landscape' | 'sensor'): void;
|
|
366
|
+
/** Toggle system bars visibility (immersive mode). Feature-detected. */
|
|
367
|
+
setImmersive(enabled: boolean): void;
|
|
368
|
+
|
|
369
|
+
// ── Screen brightness ──────────────────────────────────────────────────
|
|
370
|
+
/** Set the window screen brightness (0..1). */
|
|
371
|
+
setScreenBrightness(value: number): void;
|
|
372
|
+
/** Get the current window screen brightness (0..1). Returns 1.0 for default. */
|
|
373
|
+
getScreenBrightness(): number;
|
|
374
|
+
|
|
375
|
+
// ── Notification permission ────────────────────────────────────────────
|
|
376
|
+
/**
|
|
377
|
+
* Request the `POST_NOTIFICATIONS` permission on Android 13+.
|
|
378
|
+
* No-op on lower APIs. Uses the standard `PermissionsAndroid` flow.
|
|
379
|
+
*/
|
|
380
|
+
requestNotificationPermission(): void;
|
|
381
|
+
/** Returns true when the `MediaPlaybackService` foreground notification is active. */
|
|
382
|
+
isNotificationActive(): boolean;
|
|
383
|
+
|
|
384
|
+
// ── Debug (V12 Phase 39) ───────────────────────────────────────────────
|
|
385
|
+
/** Toggle verbose native logging (`msg-level=all`). */
|
|
386
|
+
setDebugLogging(enabled: boolean): void;
|
|
387
|
+
/** Dump all observed mpv properties to logcat. Returns the count. */
|
|
81
388
|
dumpObservedProperties(): number;
|
|
82
389
|
}
|
|
83
390
|
|
|
391
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
392
|
+
// No-op fallback (V13 Phase 50b)
|
|
393
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
394
|
+
|
|
84
395
|
const NOOP_BRIDGE: MpvPlayerModuleBridge = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
396
|
+
// Lifecycle
|
|
397
|
+
initPlayer: () => false,
|
|
398
|
+
destroy: () => {},
|
|
399
|
+
getNativePtr: () => 0,
|
|
400
|
+
|
|
401
|
+
// Playback control
|
|
402
|
+
play: () => {},
|
|
403
|
+
pause: () => {},
|
|
404
|
+
stop: () => {},
|
|
405
|
+
togglePlayPause: () => {},
|
|
91
406
|
seekAbsolute: (_positionSeconds: number) => {
|
|
92
407
|
void _positionSeconds;
|
|
93
|
-
// no-op fallback
|
|
94
408
|
},
|
|
95
|
-
|
|
409
|
+
seekForward: (_seconds: number) => {
|
|
96
410
|
void _seconds;
|
|
97
|
-
// no-op fallback
|
|
98
411
|
},
|
|
99
|
-
|
|
412
|
+
seekBackward: (_seconds: number) => {
|
|
100
413
|
void _seconds;
|
|
101
|
-
// no-op fallback
|
|
102
414
|
},
|
|
103
|
-
|
|
415
|
+
stepFrame: (_direction: 1 | -1) => {
|
|
416
|
+
void _direction;
|
|
417
|
+
},
|
|
418
|
+
screenshot: () => '',
|
|
419
|
+
|
|
420
|
+
// File loading
|
|
421
|
+
loadFile: (_path: string) => {
|
|
422
|
+
void _path;
|
|
423
|
+
},
|
|
424
|
+
loadFileWithRequestId: (_path: string, _requestId: string) => {
|
|
425
|
+
void _path;
|
|
426
|
+
void _requestId;
|
|
427
|
+
},
|
|
428
|
+
loadPlaylist: (_paths: string[], _startIndex?: number) => {
|
|
429
|
+
void _paths;
|
|
430
|
+
void _startIndex;
|
|
431
|
+
},
|
|
432
|
+
getFileInfo: () => '{}',
|
|
433
|
+
getVideoParams: () => '{}',
|
|
434
|
+
captureThumbnail: (_uri: string) => {
|
|
435
|
+
void _uri;
|
|
436
|
+
return '';
|
|
437
|
+
},
|
|
438
|
+
grantPersistablePermission: (_uri: string) => {
|
|
439
|
+
void _uri;
|
|
440
|
+
},
|
|
441
|
+
verifyContentUri: (_uri: string) => {
|
|
442
|
+
void _uri;
|
|
443
|
+
return true;
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
// Tracks
|
|
447
|
+
getTracks: () => '[]',
|
|
448
|
+
selectTrack: (_trackId: number) => {
|
|
449
|
+
void _trackId;
|
|
450
|
+
},
|
|
451
|
+
cycleTrack: (_type: 'video' | 'audio' | 'sub') => {
|
|
452
|
+
void _type;
|
|
453
|
+
},
|
|
454
|
+
setTrack: (_type: 'video' | 'audio' | 'sub', _trackId: number) => {
|
|
455
|
+
void _type;
|
|
456
|
+
void _trackId;
|
|
457
|
+
},
|
|
458
|
+
setTrackVisibility: (_trackType: string, _visible: boolean) => {
|
|
459
|
+
void _trackType;
|
|
460
|
+
void _visible;
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
// Chapters
|
|
464
|
+
getChapters: () => '[]',
|
|
465
|
+
seekChapter: (_direction: 1 | -1) => {
|
|
466
|
+
void _direction;
|
|
467
|
+
},
|
|
468
|
+
getCurrentChapter: () => '{}',
|
|
469
|
+
|
|
470
|
+
// Volume / audio
|
|
471
|
+
setVolume: (_volume: number) => {
|
|
472
|
+
void _volume;
|
|
473
|
+
},
|
|
474
|
+
getVolume: () => 100,
|
|
475
|
+
setMuted: (_muted: boolean) => {
|
|
476
|
+
void _muted;
|
|
477
|
+
},
|
|
478
|
+
getMuted: () => false,
|
|
479
|
+
isMuted: () => false,
|
|
480
|
+
getAudioDevices: () => '[]',
|
|
481
|
+
setAudioDevice: (_deviceName: string) => {
|
|
482
|
+
void _deviceName;
|
|
483
|
+
},
|
|
484
|
+
toggleMute: () => {},
|
|
485
|
+
|
|
486
|
+
// Speed / loop
|
|
487
|
+
setSpeed: (_speed: number) => {
|
|
488
|
+
void _speed;
|
|
489
|
+
},
|
|
490
|
+
getSpeed: () => 1,
|
|
491
|
+
setLoopMode: (_mode: MpvLoopMode) => {
|
|
492
|
+
void _mode;
|
|
493
|
+
},
|
|
494
|
+
getLoopMode: () => 'none',
|
|
495
|
+
setPlaylistLoop: (_loop: boolean) => {
|
|
496
|
+
void _loop;
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
// Properties
|
|
500
|
+
getProperty: (_name: string) => {
|
|
501
|
+
void _name;
|
|
502
|
+
return '';
|
|
503
|
+
},
|
|
504
|
+
setProperty: (_name: string, _value: unknown) => {
|
|
505
|
+
void _name;
|
|
506
|
+
void _value;
|
|
507
|
+
},
|
|
508
|
+
observeProperty: (_name: string) => {
|
|
509
|
+
void _name;
|
|
510
|
+
},
|
|
511
|
+
unobserveProperty: (_name: string) => {
|
|
512
|
+
void _name;
|
|
513
|
+
},
|
|
514
|
+
|
|
515
|
+
// Filters
|
|
516
|
+
setVideoFilter: (_filter: string, _enabled: boolean) => {
|
|
517
|
+
void _filter;
|
|
518
|
+
void _enabled;
|
|
519
|
+
},
|
|
520
|
+
setAudioFilter: (_filter: string, _enabled: boolean) => {
|
|
521
|
+
void _filter;
|
|
522
|
+
void _enabled;
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
// Playlist
|
|
526
|
+
getPlaylist: () => '[]',
|
|
527
|
+
playlistNext: () => {},
|
|
528
|
+
playlistPrev: () => {},
|
|
529
|
+
playlistRemove: (_index: number) => {
|
|
530
|
+
void _index;
|
|
531
|
+
},
|
|
532
|
+
playlistShuffle: () => {},
|
|
533
|
+
playlistClear: () => {},
|
|
534
|
+
|
|
535
|
+
// State queries
|
|
536
|
+
getPosition: () => 0,
|
|
537
|
+
getDuration: () => 0,
|
|
538
|
+
getPlaybackState: () => 'idle',
|
|
539
|
+
|
|
540
|
+
// Activity launch
|
|
541
|
+
openPlayer: (_uri: string, _title: string | null, _type: 'video' | 'audio', _startPositionMs: number) => {
|
|
542
|
+
void _uri;
|
|
543
|
+
void _title;
|
|
544
|
+
void _type;
|
|
545
|
+
void _startPositionMs;
|
|
546
|
+
return Promise.resolve(false);
|
|
547
|
+
},
|
|
548
|
+
getLaunchParams: () => null,
|
|
549
|
+
|
|
550
|
+
// Config
|
|
551
|
+
setConfig: (_configJson: string) => {
|
|
552
|
+
void _configJson;
|
|
553
|
+
return Promise.resolve(0);
|
|
554
|
+
},
|
|
555
|
+
|
|
556
|
+
// PiP
|
|
557
|
+
enterPip: (_chapterTitle?: string, _progressPct?: string) => {
|
|
558
|
+
void _chapterTitle;
|
|
559
|
+
void _progressPct;
|
|
560
|
+
},
|
|
561
|
+
exitPip: () => {},
|
|
562
|
+
exitPipAndFinish: () => {},
|
|
563
|
+
|
|
564
|
+
// Keep screen on
|
|
565
|
+
setKeepScreenOn: (_enabled: boolean) => {
|
|
566
|
+
void _enabled;
|
|
567
|
+
},
|
|
568
|
+
|
|
569
|
+
// Orientation / immersive
|
|
570
|
+
setOrientation: (_mode: 'portrait' | 'landscape' | 'sensor') => {
|
|
571
|
+
void _mode;
|
|
572
|
+
},
|
|
573
|
+
setImmersive: (_enabled: boolean) => {
|
|
574
|
+
void _enabled;
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
// Brightness
|
|
578
|
+
setScreenBrightness: (_value: number) => {
|
|
579
|
+
void _value;
|
|
580
|
+
},
|
|
581
|
+
getScreenBrightness: () => 1.0,
|
|
582
|
+
|
|
583
|
+
// Notification
|
|
584
|
+
requestNotificationPermission: () => {},
|
|
585
|
+
isNotificationActive: () => false,
|
|
586
|
+
|
|
587
|
+
// Debug
|
|
104
588
|
setDebugLogging: (_enabled: boolean) => {
|
|
105
589
|
void _enabled;
|
|
106
|
-
// no-op fallback
|
|
107
590
|
},
|
|
108
591
|
dumpObservedProperties: () => 0,
|
|
109
592
|
};
|
|
110
593
|
|
|
594
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
595
|
+
// Resolution + singleton
|
|
596
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Cached `NativeEventEmitter` instance, lazily created once we know
|
|
600
|
+
* the native module is wired. Laziness avoids the warning React
|
|
601
|
+
* Native emits when you construct an emitter against an absent
|
|
602
|
+
* module.
|
|
603
|
+
*/
|
|
604
|
+
let _emitter: NativeEventEmitter | null = null;
|
|
605
|
+
|
|
111
606
|
/**
|
|
112
607
|
* Resolve the typed bridge module lazily. Returns `null` (caller
|
|
113
608
|
* falls back to no-op bridge) when:
|
|
114
609
|
* - `NativeModules.MpvPlayerModule` is absent (web / Storybook /
|
|
115
610
|
* unit tests without the native module installed),
|
|
116
|
-
* - the module is present but missing
|
|
611
|
+
* - the module is present but missing the core methods (Phase 50
|
|
117
612
|
* stub in jest tests).
|
|
118
613
|
*
|
|
119
614
|
* We deliberately swallow errors here and return null — a missing
|
|
120
615
|
* bridge is a routine state during development (running jest with
|
|
121
616
|
* the module installed but the native side not yet wired). Logging
|
|
122
617
|
* once per call would spam the console.
|
|
618
|
+
*
|
|
619
|
+
* V13 Phase 50: the bridge-presence check now also requires
|
|
620
|
+
* `loadFile` (the cheapest method that doesn't depend on
|
|
621
|
+
* `initPlayer()` having been called) — older V12 stubs only had
|
|
622
|
+
* the 9 methods DefaultControls needed.
|
|
123
623
|
*/
|
|
124
624
|
function resolveBridge(): MpvPlayerModuleBridge | null {
|
|
125
625
|
const mod = (NativeModules as Record<string, unknown>).MpvPlayerModule;
|
|
@@ -128,13 +628,30 @@ function resolveBridge(): MpvPlayerModuleBridge | null {
|
|
|
128
628
|
if (
|
|
129
629
|
typeof m.play !== 'function' ||
|
|
130
630
|
typeof m.pause !== 'function' ||
|
|
131
|
-
typeof m.seekAbsolute !== 'function'
|
|
631
|
+
typeof m.seekAbsolute !== 'function' ||
|
|
632
|
+
typeof m.loadFile !== 'function'
|
|
132
633
|
) {
|
|
133
634
|
return null;
|
|
134
635
|
}
|
|
135
|
-
return
|
|
636
|
+
return mod as MpvPlayerModuleBridge;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Resolve the event emitter lazily. Returns `null` when the bridge
|
|
641
|
+
* is absent (so `subscribePlayerEvent` becomes a no-op).
|
|
642
|
+
*/
|
|
643
|
+
function resolveEmitter(): NativeEventEmitter | null {
|
|
644
|
+
if (_emitter !== null) return _emitter;
|
|
645
|
+
const mod = (NativeModules as Record<string, unknown>).MpvPlayerModule;
|
|
646
|
+
if (mod == null || typeof mod !== 'object') return null;
|
|
647
|
+
_emitter = new NativeEventEmitter(mod as any);
|
|
648
|
+
return _emitter;
|
|
136
649
|
}
|
|
137
650
|
|
|
651
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
652
|
+
// Public API
|
|
653
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
654
|
+
|
|
138
655
|
/**
|
|
139
656
|
* Phase 39: enable verbose logging from the TypeScript layer.
|
|
140
657
|
* Sets the module-scoped flag that the internal `dlog` helper
|
|
@@ -180,24 +697,89 @@ export function dumpObservedProperties(): number {
|
|
|
180
697
|
export { dlog };
|
|
181
698
|
|
|
182
699
|
/**
|
|
183
|
-
* Phase
|
|
184
|
-
*
|
|
185
|
-
* methods resolve silently.
|
|
186
|
-
*
|
|
187
|
-
* Consumers (default controls + custom controls) should always
|
|
188
|
-
* import this getter rather than reach into `NativeModules`
|
|
700
|
+
* V13 Phase 50: live bridge (or no-op fallback). Consumers should
|
|
701
|
+
* always import this getter rather than reach into `NativeModules`
|
|
189
702
|
* directly — the no-op fallback is what keeps `DefaultControls`
|
|
190
|
-
* renderable in jest tests + Storybook + web
|
|
191
|
-
*
|
|
192
|
-
* Future phases may add a `subscribe(eventName)` for mpv property
|
|
193
|
-
* observers; the bridge contract will grow alongside.
|
|
703
|
+
* and consumer code renderable in jest tests + Storybook + web
|
|
704
|
+
* previews.
|
|
194
705
|
*/
|
|
195
706
|
export function getMpvPlayerModule(): MpvPlayerModuleBridge {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
// anything?" — the answer is usually "you got the no-op fallback
|
|
200
|
-
// because the native module isn't wired".
|
|
201
|
-
dlog('getMpvPlayerModule: resolved', resolveBridge() ? 'live bridge' : 'no-op fallback');
|
|
707
|
+
const live = resolveBridge();
|
|
708
|
+
const bridge = live ?? NOOP_BRIDGE;
|
|
709
|
+
dlog('getMpvPlayerModule: resolved', live ? 'live bridge' : 'no-op fallback');
|
|
202
710
|
return bridge;
|
|
203
711
|
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* V13 Phase 50c: subscribe to a native event. Returns an
|
|
715
|
+
* unsubscribe function that callers should invoke from
|
|
716
|
+
* `useEffect` cleanup. When the bridge is absent (jest, web
|
|
717
|
+
* preview), returns a no-op unsubscribe so cleanup is safe.
|
|
718
|
+
*/
|
|
719
|
+
export function subscribePlayerEvent<E extends PlayerEventName>(
|
|
720
|
+
event: E,
|
|
721
|
+
handler: (payload: PlayerEventPayloads[E]) => void,
|
|
722
|
+
): () => void {
|
|
723
|
+
const emitter = resolveEmitter();
|
|
724
|
+
if (emitter === null) {
|
|
725
|
+
dlog('subscribePlayerEvent: no emitter for', event);
|
|
726
|
+
return () => {
|
|
727
|
+
// no-op unsubscribe (bridge absent)
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
dlog('subscribePlayerEvent: subscribing to', event);
|
|
731
|
+
const subscription = emitter.addListener(event, handler);
|
|
732
|
+
return () => {
|
|
733
|
+
dlog('subscribePlayerEvent: unsubscribing from', event);
|
|
734
|
+
subscription.remove();
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* V13 Phase 50c: remove all listeners for a single event, or
|
|
740
|
+
* every event when no argument is passed. Mirrors the consumer's
|
|
741
|
+
* old `MpvPlayer.removeAllListeners(event?)` API.
|
|
742
|
+
*/
|
|
743
|
+
export function removeAllListeners(event?: PlayerEventName): void {
|
|
744
|
+
const emitter = resolveEmitter();
|
|
745
|
+
if (emitter === null) return;
|
|
746
|
+
dlog('removeAllListeners: event=', event ?? '(all)');
|
|
747
|
+
// RN's NativeEventEmitter.removeAllListeners requires an event name;
|
|
748
|
+
// there is no no-arg overload. When called without an argument we
|
|
749
|
+
// iterate every known event and remove each one.
|
|
750
|
+
if (event === undefined) {
|
|
751
|
+
for (const name of ALL_PLAYER_EVENTS) {
|
|
752
|
+
emitter.removeAllListeners(name);
|
|
753
|
+
}
|
|
754
|
+
} else {
|
|
755
|
+
emitter.removeAllListeners(event);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/** All 22 player event names — used by `removeAllListeners()` to iterate when no event is specified. */
|
|
760
|
+
const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
761
|
+
'onFileLoaded',
|
|
762
|
+
'onPlaybackStateChanged',
|
|
763
|
+
'onPositionChanged',
|
|
764
|
+
'onDurationChanged',
|
|
765
|
+
'onPropertyChanged',
|
|
766
|
+
'onTracksChanged',
|
|
767
|
+
'onChapterChanged',
|
|
768
|
+
'onVideoParamsChanged',
|
|
769
|
+
'onError',
|
|
770
|
+
'onBuffering',
|
|
771
|
+
'onCacheState',
|
|
772
|
+
'onSeekable',
|
|
773
|
+
'onSeeking',
|
|
774
|
+
'onEndFile',
|
|
775
|
+
'onPlaybackRestart',
|
|
776
|
+
'onEndReached',
|
|
777
|
+
'onAudioDeviceChanged',
|
|
778
|
+
'onVolumeChanged',
|
|
779
|
+
'onSpeedChanged',
|
|
780
|
+
'videoReconfig',
|
|
781
|
+
'onPipModeChanged',
|
|
782
|
+
'onPipPlayPause',
|
|
783
|
+
'onPipExpand',
|
|
784
|
+
'onPipClose',
|
|
785
|
+
];
|