@simba-dev/react-native-media-player 2.0.1 → 3.0.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 +317 -560
- package/android/src/main/cpp/main.cpp +117 -17
- package/android/src/main/java/com/simba/player/PipManager.kt +13 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +177 -6
- package/android/src/main/java/com/simba/player/mpv/PipAutoEnterPolicy.kt +54 -0
- package/package.json +11 -2
- package/src/components/PlayerProvider.tsx +5 -5
- package/src/index.ts +25 -12
- package/android/src/test/java/com/simba/player/PipActionReceiverTest.kt +0 -123
- package/android/src/test/java/com/simba/player/PipManagerTest.kt +0 -281
- package/android/src/test/java/com/simba/player/TestApplication.kt +0 -26
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleNullInstanceTest.kt +0 -117
- package/android/src/test/java/com/simba/player/mpv/MpvBridgeModuleTest.kt +0 -212
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewRegistryTest.kt +0 -120
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewTest.kt +0 -249
- package/scripts/override_react_methods.js +0 -184
- package/scripts/override_react_methods.py +0 -150
- package/src/bridge/__tests__/MpvPlayerModule.test.ts +0 -163
- package/src/bridge/__tests__/debugMode.test.ts +0 -138
- package/src/bridge/__tests__/errorContract.test.ts +0 -175
- package/src/bridge/__tests__/loadAndPlay.startPosition.test.tsx +0 -142
- package/src/components/PlayerRoot.tsx +0 -124
- package/src/components/PlayerSurface.tsx +0 -62
- package/src/components/__tests__/PlayerProvider.performance.test.tsx +0 -242
- package/src/components/__tests__/PlayerProvider.progressContext.test.tsx +0 -194
- package/src/components/__tests__/PlayerProvider.test.tsx +0 -558
- package/src/components/__tests__/PlayerRoot.test.tsx +0 -71
- package/src/components/__tests__/SimbaVideo.test.tsx +0 -164
- package/src/hooks/__tests__/resolveStreamType.test.ts +0 -159
- package/src/hooks/__tests__/useLaunchPlayback.test.tsx +0 -278
- package/src/hooks/__tests__/useResumeThumbnail.test.ts +0 -154
- package/src/stores/__tests__/playerQueueSelectionStore.test.ts +0 -73
- package/src/stores/__tests__/playerQueueStore.test.ts +0 -171
- package/src/types/__tests__/config.test.ts +0 -188
- package/src/types/__tests__/player.pipAnswer.test.tsx +0 -87
- package/src/types/__tests__/player.pipArity.test.tsx +0 -74
- package/src/types/__tests__/player.test.tsx +0 -1365
- package/src/types/__tests__/playerLoading.test.ts +0 -170
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the Phase 38 error contract — verifies the typed bridge
|
|
3
|
-
* wrapper emits structured error events that JS consumers can
|
|
4
|
-
* listen to without writing try/catch boilerplate.
|
|
5
|
-
*
|
|
6
|
-
* Spec §38 — Error handling & recovery.
|
|
7
|
-
*
|
|
8
|
-
* Test surface:
|
|
9
|
-
* - The typed `MpvPlayerModuleBridge` interface is the source of
|
|
10
|
-
* truth for the consumer-facing error shape
|
|
11
|
-
* - The no-op fallback bridge (used in jest unit tests + Storybook
|
|
12
|
-
* + web previews) doesn't throw on error scenarios
|
|
13
|
-
* - Promise-returning bridge methods reject with structured codes
|
|
14
|
-
*
|
|
15
|
-
* Note: most error-handling lives in the Kotlin bridge (emitErrorEvent)
|
|
16
|
-
* and can only be exercised end-to-end on a real device. The unit
|
|
17
|
-
* tests here cover the TypeScript-side contract: the typed wrapper
|
|
18
|
-
* interface, the no-op fallback, and the consumer-facing types.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { getMpvPlayerModule } from '../MpvPlayerModule';
|
|
22
|
-
|
|
23
|
-
describe('Phase 38 — error contract (TypeScript side)', () => {
|
|
24
|
-
it('getMpvPlayerModule returns a bridge even when native module is absent', async () => {
|
|
25
|
-
// The no-op fallback is what keeps jest unit tests renderable
|
|
26
|
-
// without a real native module. Phase 38 guarantees it doesn't
|
|
27
|
-
// throw on any error scenario (it just no-ops).
|
|
28
|
-
const bridge = getMpvPlayerModule();
|
|
29
|
-
expect(bridge).toBeDefined();
|
|
30
|
-
expect(typeof bridge.play).toBe('function');
|
|
31
|
-
expect(typeof bridge.pause).toBe('function');
|
|
32
|
-
|
|
33
|
-
// The native module isn't wired in jest — verify by checking
|
|
34
|
-
// that a setConfig call (the only Promise-returning method)
|
|
35
|
-
// resolves immediately rather than rejecting with the documented
|
|
36
|
-
// E_CONFIG_PARSE_FAILED code. V13 Phase 50: setConfig now
|
|
37
|
-
// resolves with the count of parsed top-level keys (matches the
|
|
38
|
-
// Kotlin implementation at MpvBridgeModule.kt). The no-op
|
|
39
|
-
// fallback resolves to 0.
|
|
40
|
-
await expect(bridge.setConfig('not-valid-json{')).resolves.toBe(0);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('no-op bridge methods do not throw on edge-case inputs', () => {
|
|
44
|
-
// The no-op fallback should be safe to call with any arguments
|
|
45
|
-
// — including malformed input that the typed bridge would reject.
|
|
46
|
-
// This guarantees the fallback doesn't crash React render passes.
|
|
47
|
-
const bridge = getMpvPlayerModule();
|
|
48
|
-
expect(() => bridge.play()).not.toThrow();
|
|
49
|
-
expect(() => bridge.pause()).not.toThrow();
|
|
50
|
-
expect(() => bridge.seekAbsolute(NaN)).not.toThrow();
|
|
51
|
-
expect(() => bridge.seekAbsolute(-1)).not.toThrow();
|
|
52
|
-
expect(() => bridge.seekAbsolute(Infinity)).not.toThrow();
|
|
53
|
-
expect(() => bridge.seekBackward(NaN)).not.toThrow();
|
|
54
|
-
expect(() => bridge.seekForward(NaN)).not.toThrow();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('no-op bridge setConfig resolves (does not reject) for any input', async () => {
|
|
58
|
-
// The real bridge rejects setConfig with E_CONFIG_PARSE_FAILED
|
|
59
|
-
// for malformed JSON. The no-op fallback resolves silently —
|
|
60
|
-
// this is by design: jest unit tests should not crash on
|
|
61
|
-
// malformed config; the real parsing happens at runtime on a
|
|
62
|
-
// device. V13 Phase 50: the resolution value is the parsed-key
|
|
63
|
-
// count (0 for malformed input, matches Kotlin).
|
|
64
|
-
const bridge = getMpvPlayerModule();
|
|
65
|
-
await expect(bridge.setConfig('')).resolves.toBe(0);
|
|
66
|
-
await expect(bridge.setConfig('not-json')).resolves.toBe(0);
|
|
67
|
-
await expect(bridge.setConfig('{')).resolves.toBe(0);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('typed bridge interface exposes the 6 documented methods', () => {
|
|
71
|
-
// Pin the contract: getMpvPlayerModule returns a bridge with at
|
|
72
|
-
// least these 6 methods (Phase 24 contract, unchanged by Phase
|
|
73
|
-
// 38). The native bridge exposes more methods (the full Kotlin
|
|
74
|
-
// API surface); this test pins the MINIMUM, not the exact list.
|
|
75
|
-
const bridge = getMpvPlayerModule();
|
|
76
|
-
// The 6 typed-method names that the consumer-facing wrapper
|
|
77
|
-
// documents as the public API
|
|
78
|
-
const EXPECTED_METHODS = [
|
|
79
|
-
'pause',
|
|
80
|
-
'play',
|
|
81
|
-
'seekAbsolute',
|
|
82
|
-
'seekBackward',
|
|
83
|
-
'seekForward',
|
|
84
|
-
'setConfig',
|
|
85
|
-
];
|
|
86
|
-
EXPECTED_METHODS.forEach((method) => {
|
|
87
|
-
expect(typeof (bridge as unknown as Record<string, unknown>)[method]).toBe('function');
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('typed bridge methods are callable', () => {
|
|
92
|
-
// The Phase 38 error contract relies on consumers being able to
|
|
93
|
-
// call each of the 6 documented methods without throwing. The
|
|
94
|
-
// return-value contract is documented in MpvPlayerModule.ts
|
|
95
|
-
// (setConfig returns Promise<void>; the other 5 return void),
|
|
96
|
-
// but a refactor that changes the return type would be caught
|
|
97
|
-
// by the TS compiler — not by these unit tests. We just verify
|
|
98
|
-
// each method is callable without throwing.
|
|
99
|
-
const bridge = getMpvPlayerModule();
|
|
100
|
-
expect(() => bridge.play()).not.toThrow();
|
|
101
|
-
expect(() => bridge.pause()).not.toThrow();
|
|
102
|
-
expect(() => bridge.seekAbsolute(0)).not.toThrow();
|
|
103
|
-
expect(() => bridge.seekBackward(0)).not.toThrow();
|
|
104
|
-
expect(() => bridge.seekForward(0)).not.toThrow();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('Phase 38 — error code constants (consumer contract)', () => {
|
|
109
|
-
/**
|
|
110
|
-
* The error codes emitted by MpvBridgeModule are documented in
|
|
111
|
-
* SIMBA_PLAYER_MODULE_V12_ERROR_CONTRACT.md §2.1. These tests
|
|
112
|
-
* pin the codes so a refactor doesn't accidentally rename them
|
|
113
|
-
* (which would silently break every consumer's switch statement).
|
|
114
|
-
*
|
|
115
|
-
* We don't import the codes from the native module (they're
|
|
116
|
-
* emitted as event payloads, not exported constants) — instead
|
|
117
|
-
* we test that the documentation in ERROR_CONTRACT.md matches
|
|
118
|
-
* what the bridge emits. The Kotlin bridge emits these strings
|
|
119
|
-
* as the `code` field of the `onError` payload.
|
|
120
|
-
*
|
|
121
|
-
* If any of these change, both ERROR_CONTRACT.md §2.1 AND the
|
|
122
|
-
* Kotlin emitErrorEvent() callers must change together.
|
|
123
|
-
*/
|
|
124
|
-
const DOCUMENTED_ERROR_CODES = [
|
|
125
|
-
'E_NOT_INITIALIZED',
|
|
126
|
-
'E_INVALID_TYPE',
|
|
127
|
-
'E_NO_ACTIVITY',
|
|
128
|
-
'E_ACTIVITY_NOT_FOUND',
|
|
129
|
-
'E_SECURITY',
|
|
130
|
-
'E_OPEN_PLAYER_FAILED',
|
|
131
|
-
'E_CONFIG_PARSE_FAILED',
|
|
132
|
-
'E_NETWORK_FAILURE',
|
|
133
|
-
'E_DECODE_FAILED',
|
|
134
|
-
'E_UNSUPPORTED_CODEC',
|
|
135
|
-
'E_FILE_NOT_FOUND',
|
|
136
|
-
'E_RENDERER_GONE',
|
|
137
|
-
'E_OUT_OF_MEMORY',
|
|
138
|
-
'E_AUDIO_FOCUS_LOST',
|
|
139
|
-
'E_SURFACE_LOST',
|
|
140
|
-
// v1.17.0 — the mpv error codes, mapped from `mpv_error` in mpv's
|
|
141
|
-
// `include/mpv/client.h`. These replaced the "every terminal
|
|
142
|
-
// failure is E_RENDERER_GONE" catch-all, which made a load failure
|
|
143
|
-
// indistinguishable from a dead video output.
|
|
144
|
-
'E_LOAD_FAILED',
|
|
145
|
-
'E_AUDIO_INIT_FAILED',
|
|
146
|
-
'E_VIDEO_INIT_FAILED',
|
|
147
|
-
'E_NOTHING_TO_PLAY',
|
|
148
|
-
'E_UNKNOWN_FORMAT',
|
|
149
|
-
'E_GENERIC',
|
|
150
|
-
'E_NOT_IMPLEMENTED',
|
|
151
|
-
'E_INVALID_PARAMETER',
|
|
152
|
-
'E_OPTION_NOT_FOUND',
|
|
153
|
-
'E_PROPERTY_NOT_FOUND',
|
|
154
|
-
'E_COMMAND_FAILED',
|
|
155
|
-
];
|
|
156
|
-
|
|
157
|
-
it('exposes the 26 documented error codes as a frozen contract', () => {
|
|
158
|
-
// The list itself is not exported from the module — it's
|
|
159
|
-
// documented in ERROR_CONTRACT.md. This test pins the list so
|
|
160
|
-
// a drift between docs and code fails CI.
|
|
161
|
-
expect(DOCUMENTED_ERROR_CODES).toHaveLength(26);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('error codes follow the E_UPPER_SNAKE_CASE convention', () => {
|
|
165
|
-
// Stable naming convention — any future code should match.
|
|
166
|
-
DOCUMENTED_ERROR_CODES.forEach((code) => {
|
|
167
|
-
expect(code).toMatch(/^E_[A-Z_]+$/);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('error codes are unique', () => {
|
|
172
|
-
const unique = new Set(DOCUMENTED_ERROR_CODES);
|
|
173
|
-
expect(unique.size).toBe(DOCUMENTED_ERROR_CODES.length);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The resume contract: a launch that resumes must START at the saved
|
|
3
|
-
* position, and the start position must be part of the LOAD.
|
|
4
|
-
*
|
|
5
|
-
* ## The defect this pins
|
|
6
|
-
*
|
|
7
|
-
* A resuming launch used to do `loadFile(uri)` and then
|
|
8
|
-
* `seekAbsolute(seconds)`. mpv **refuses** a seek until the file has
|
|
9
|
-
* actually opened — `cmd_seek` bails out with `cmd->success = false`
|
|
10
|
-
* while `!mpctx->playback_initialized` (mpv `player/command.c`) — and
|
|
11
|
-
* `playback_initialized` is only set once the file is open (mpv
|
|
12
|
-
* `player/loadfile.c`, immediately before `MPV_EVENT_FILE_LOADED`).
|
|
13
|
-
*
|
|
14
|
-
* The native side discarded mpv's return code, so the refusal was
|
|
15
|
-
* completely silent: the file played from 0:00, the transport bar
|
|
16
|
-
* truthfully showed 0:00, and the resume simply did not happen. Measured
|
|
17
|
-
* on device: `seekAbsolute position=1060.727` was logged and mpv never
|
|
18
|
-
* emitted a `seek` event — while a manual scrub (a seek issued after the
|
|
19
|
-
* file was open) landed exactly where it was aimed.
|
|
20
|
-
*
|
|
21
|
-
* The fix writes mpv's own `start` option BEFORE the load. mpv reads it
|
|
22
|
-
* while the file opens, so the start position becomes part of the load
|
|
23
|
-
* and cannot be dropped.
|
|
24
|
-
*
|
|
25
|
-
* ## What is pinned here
|
|
26
|
-
*
|
|
27
|
-
* - the start position is written, in SECONDS, before the load;
|
|
28
|
-
* - the load does NOT issue a `seek` (that was the defect);
|
|
29
|
-
* - the start position is written on EVERY load, including `0` — mpv's
|
|
30
|
-
* `start` option is persistent, so skipping the write would carry the
|
|
31
|
-
* last resume position into the NEXT file;
|
|
32
|
-
* - a rejected write still loads and plays the file;
|
|
33
|
-
* - `onPlaybackRestart` does not zero the position — the position is
|
|
34
|
-
* owned by `time-pos` and by nothing else.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
import { NativeModules } from 'react-native';
|
|
38
|
-
import { loadAndPlay } from '../loadAndPlay';
|
|
39
|
-
import type { MpvPlayerModuleBridge } from '../MpvPlayerModule';
|
|
40
|
-
import {
|
|
41
|
-
applyPlayerEvent,
|
|
42
|
-
DEFAULT_PROGRESS,
|
|
43
|
-
DEFAULT_STATE,
|
|
44
|
-
} from '../../types/player';
|
|
45
|
-
|
|
46
|
-
const bridge = () =>
|
|
47
|
-
NativeModules.MpvPlayerModule as unknown as MpvPlayerModuleBridge & {
|
|
48
|
-
setProperty: jest.Mock;
|
|
49
|
-
loadFile: jest.Mock;
|
|
50
|
-
play: jest.Mock;
|
|
51
|
-
seekAbsolute: jest.Mock;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function clearBridgeMocks() {
|
|
55
|
-
for (const key of Object.keys(bridge())) {
|
|
56
|
-
const fn = (bridge() as unknown as Record<string, unknown>)[key];
|
|
57
|
-
if (typeof (fn as { mockClear?: () => void })?.mockClear === 'function') {
|
|
58
|
-
(fn as { mockClear: () => void }).mockClear();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const URI = 'https://example.test/movie.mp4';
|
|
64
|
-
|
|
65
|
-
describe('loadAndPlay — the start position is part of the load', () => {
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
clearBridgeMocks();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('writes the start position in SECONDS before the load', () => {
|
|
71
|
-
// 90 000 ms is 90 s. A unit error here seeks to the wrong place with
|
|
72
|
-
// no error anywhere.
|
|
73
|
-
loadAndPlay(bridge(), {uri: URI, startPositionMs: 90_000});
|
|
74
|
-
|
|
75
|
-
const order: string[] = [];
|
|
76
|
-
bridge().setProperty.mockImplementation((name: string) => {
|
|
77
|
-
order.push(`setProperty:${name}`);
|
|
78
|
-
});
|
|
79
|
-
bridge().loadFile.mockImplementation(() => {
|
|
80
|
-
order.push('loadFile');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
loadAndPlay(bridge(), {uri: URI, startPositionMs: 90_000});
|
|
84
|
-
|
|
85
|
-
expect(bridge().setProperty).toHaveBeenCalledWith('options/start', '90.000');
|
|
86
|
-
expect(order).toEqual(['setProperty:options/start', 'loadFile']);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('does NOT issue a seek at load time — mpv refuses it', () => {
|
|
90
|
-
// The defect: `loadFile` + `seekAbsolute` in the same tick. mpv
|
|
91
|
-
// refuses the seek (playback is not initialised yet) and the refusal
|
|
92
|
-
// is silent, so the resume plays from 0:00.
|
|
93
|
-
loadAndPlay(bridge(), {uri: URI, startPositionMs: 90_000});
|
|
94
|
-
expect(bridge().seekAbsolute).not.toHaveBeenCalled();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('always writes the start position, so a resume cannot leak into the next file', () => {
|
|
98
|
-
// mpv's `start` option is persistent. A plain load MUST write 0, or
|
|
99
|
-
// the next file starts where the last one was resumed to.
|
|
100
|
-
loadAndPlay(bridge(), {uri: URI});
|
|
101
|
-
expect(bridge().setProperty).toHaveBeenCalledWith('options/start', '0.000');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('writes 0 for a negative or non-finite start position', () => {
|
|
105
|
-
loadAndPlay(bridge(), {uri: URI, startPositionMs: -5_000});
|
|
106
|
-
expect(bridge().setProperty).toHaveBeenCalledWith('options/start', '0.000');
|
|
107
|
-
|
|
108
|
-
clearBridgeMocks();
|
|
109
|
-
loadAndPlay(bridge(), {uri: URI, startPositionMs: Number.NaN});
|
|
110
|
-
expect(bridge().setProperty).toHaveBeenCalledWith('options/start', '0.000');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('still loads and plays the file when the option write is rejected', () => {
|
|
114
|
-
// A rejected option must never cost the user their video. mpv plays
|
|
115
|
-
// the file from the beginning and the resume is simply not honoured.
|
|
116
|
-
bridge().setProperty.mockImplementationOnce(() => {
|
|
117
|
-
throw new Error('property rejected');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
loadAndPlay(bridge(), {uri: URI, startPositionMs: 90_000});
|
|
121
|
-
|
|
122
|
-
expect(bridge().loadFile).toHaveBeenCalledWith(URI);
|
|
123
|
-
expect(bridge().play).toHaveBeenCalledTimes(1);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('onPlaybackRestart does not own the position', () => {
|
|
128
|
-
it('keeps the position it was given', () => {
|
|
129
|
-
// mpv fires `playback-restart` when playback (re)starts — including
|
|
130
|
-
// right after a seek. Zeroing the position there restarted the
|
|
131
|
-
// transport bar's clock at 0:00 while the video sat at the position
|
|
132
|
-
// the user had just seeked to (or resumed to).
|
|
133
|
-
const progress = {...DEFAULT_PROGRESS, positionMs: 1_060_727};
|
|
134
|
-
const state = {...DEFAULT_STATE, isPlaying: false, positionMs: 1_060_727};
|
|
135
|
-
|
|
136
|
-
const next = applyPlayerEvent(state, progress, 'onPlaybackRestart', {});
|
|
137
|
-
|
|
138
|
-
expect(next.progress.positionMs).toBe(1_060_727);
|
|
139
|
-
expect(next.state.positionMs).toBe(1_060_727);
|
|
140
|
-
expect(next.state.isPlaying).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import { useRenderControls } from './PlayerProvider';
|
|
4
|
-
import { useLaunchPlayback } from '../hooks/useLaunchPlayback';
|
|
5
|
-
import type { LaunchParams } from '../bridge/MpvPlayerModule';
|
|
6
|
-
import { PlayerSurface } from './PlayerSurface';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The player's root: the surface, and the consumer's controls over it.
|
|
10
|
-
*
|
|
11
|
-
* ## v2.0.0 — the library draws no chrome
|
|
12
|
-
*
|
|
13
|
-
* Before 2.0.0 this component fell back to `<DefaultControls>` — the
|
|
14
|
-
* 564-line control bundle the library used to ship — whenever the
|
|
15
|
-
* consumer did not pass `renderControls`. That fallback is **gone**.
|
|
16
|
-
* The library renders **no chrome of its own**: the consumer's
|
|
17
|
-
* `renderControls` output, or nothing at all.
|
|
18
|
-
*
|
|
19
|
-
* The overlay is mounted only when there is something to put in it, so
|
|
20
|
-
* a consumer that drives the player itself (the usual case — render
|
|
21
|
-
* `<SimbaVideo />` in your own tree) gets no phantom container over
|
|
22
|
-
* the surface.
|
|
23
|
-
*
|
|
24
|
-
* V21 F5: `launchParams` is now an explicit prop with no implicit
|
|
25
|
-
* fallback. It used to fall back to `useLaunchParams()`, which read a
|
|
26
|
-
* one-shot native queue that only a second Activity ever filled — so the
|
|
27
|
-
* fallback could not fire, and keeping it would have been a branch that
|
|
28
|
-
* looked live and was not. Pass the payload in, or drive loading
|
|
29
|
-
* yourself with the exported `useLaunchPlayback`.
|
|
30
|
-
*
|
|
31
|
-
* Renders the full player UI in two layers:
|
|
32
|
-
* 1. **`<PlayerSurface />`** (Phase 25): the JS-side placeholder
|
|
33
|
-
* for the native SurfaceView that mpv draws into. Fills the
|
|
34
|
-
* available space via `flex: 1`.
|
|
35
|
-
* 2. **Controls overlay** (Phase 23 + 24): the consumer's custom
|
|
36
|
-
* controls, via `renderControls`. Absolutely positioned over the
|
|
37
|
-
* surface so the video fills the screen and the controls layer on
|
|
38
|
-
* top.
|
|
39
|
-
*
|
|
40
|
-
* Wiring example for a consumer:
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* function App() {
|
|
45
|
-
* return (
|
|
46
|
-
* <PlayerProvider
|
|
47
|
-
* config={{ theme: { accent: '#FFD700' } }}
|
|
48
|
-
* renderControls={() => <MyCustomControls />}
|
|
49
|
-
* >
|
|
50
|
-
* <PlayerRoot />
|
|
51
|
-
* </PlayerProvider>
|
|
52
|
-
* );
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* Design notes
|
|
57
|
-
* ------------
|
|
58
|
-
* - The controls overlay uses `position: 'absolute'` + the four
|
|
59
|
-
* insets (`top / left / right / bottom: 0`) so it stretches over
|
|
60
|
-
* the surface without affecting its layout. The surface owns the
|
|
61
|
-
* flex layout for the tree; the controls float on top.
|
|
62
|
-
* - When `renderControls` is provided, we render its output
|
|
63
|
-
* wrapped in the same absolutely-positioned overlay container,
|
|
64
|
-
* so custom controls don't need to handle their own
|
|
65
|
-
* positioning — they Just Work over the surface.
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* V22.0.0 / 1.5.8 (D-035 fix #5): optional `launchParams` prop.
|
|
69
|
-
*
|
|
70
|
-
* `<SimbaPlayerRoot>` already calls `useLaunchParams()` once at the
|
|
71
|
-
* activity boundary. If we also called it here, the second read would
|
|
72
|
-
* hit an empty one-shot queue (the first read consumed it) and we'd
|
|
73
|
-
* fall through to the `null` branch — leaving the screen with no
|
|
74
|
-
* media loaded. Letting the parent pass `launchParams` down as a
|
|
75
|
-
* prop means the player root always sees the resolved payload.
|
|
76
|
-
*
|
|
77
|
-
* Direct consumers that mount `<PlayerRoot />` without
|
|
78
|
-
* `<SimbaPlayerRoot>` (rare; legacy V11/V12 patterns) keep working:
|
|
79
|
-
* when `launchParams` is left `undefined` we fall back to the hook,
|
|
80
|
-
* which reads the queue exactly once and returns `null` on
|
|
81
|
-
* subsequent mounts.
|
|
82
|
-
*/
|
|
83
|
-
export interface PlayerRootProps {
|
|
84
|
-
launchParams?: LaunchParams | null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function PlayerRoot({
|
|
88
|
-
launchParams,
|
|
89
|
-
}: PlayerRootProps = {}): React.ReactElement {
|
|
90
|
-
const renderControls = useRenderControls();
|
|
91
|
-
|
|
92
|
-
// V22.0.0 / 1.5.8 (D-035 fix #3 + #5 + #7): feed the launch URI to
|
|
93
|
-
// mpv exactly once per `(uri, startPositionMs)` payload, NOT once
|
|
94
|
-
// per render. `useLaunchPlayback` owns that contract.
|
|
95
|
-
// The effect is keyed on the URI + start position, so it fires once
|
|
96
|
-
// when the payload resolves to a real URI, then never again until
|
|
97
|
-
// the URI actually changes.
|
|
98
|
-
useLaunchPlayback(launchParams);
|
|
99
|
-
|
|
100
|
-
// The library draws no chrome. Whatever the consumer supplied is
|
|
101
|
-
// what appears over the surface; if the consumer supplied nothing,
|
|
102
|
-
// there is nothing to draw.
|
|
103
|
-
const controls = renderControls != null ? renderControls() : null;
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<View style={styles.root}>
|
|
107
|
-
<PlayerSurface />
|
|
108
|
-
{controls != null ? <View style={styles.overlay}>{controls}</View> : null}
|
|
109
|
-
</View>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const styles = StyleSheet.create({
|
|
114
|
-
root: {
|
|
115
|
-
flex: 1,
|
|
116
|
-
},
|
|
117
|
-
overlay: {
|
|
118
|
-
position: 'absolute',
|
|
119
|
-
top: 0,
|
|
120
|
-
left: 0,
|
|
121
|
-
right: 0,
|
|
122
|
-
bottom: 0,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export interface PlayerSurfaceProps {
|
|
5
|
-
/**
|
|
6
|
-
* Background color for the placeholder. Defaults to `'transparent'`,
|
|
7
|
-
* so whatever is behind it shows through to the user.
|
|
8
|
-
*
|
|
9
|
-
* **v2.0.0:** the native SurfaceView this placeholder used to stand
|
|
10
|
-
* in for is gone — the picture is `<SimbaVideo />`, in the React
|
|
11
|
-
* tree. A non-transparent value therefore paints a backdrop *over*
|
|
12
|
-
* the picture wherever the placeholder sits in front of it.
|
|
13
|
-
*/
|
|
14
|
-
backgroundColor?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A transparent, full-size **layout placeholder**.
|
|
19
|
-
*
|
|
20
|
-
* ## v2.0.0 — what this is, and is not
|
|
21
|
-
*
|
|
22
|
-
* This component used to stand in for the native SurfaceView that mpv
|
|
23
|
-
* drew into. Back then the surface was a **sibling** of the React
|
|
24
|
-
* root — pinned to `android.R.id.content` by the library's own
|
|
25
|
-
* `PlayerActivity` — and this box reserved the screen rectangle the
|
|
26
|
-
* controls overlay was positioned against.
|
|
27
|
-
*
|
|
28
|
-
* **That arrangement is gone.** The picture is now `<SimbaVideo />`:
|
|
29
|
-
* a Fabric component (`SimbaVideoView`) inside the React tree, with
|
|
30
|
-
* React Native owning its layout, its z-order and its lifecycle.
|
|
31
|
-
* Neither the library nor a host app mounts a surface at the activity
|
|
32
|
-
* root any more — a host app's Activity says so in as many words.
|
|
33
|
-
*
|
|
34
|
-
* What is left is a transparent `flex: 1` box: a full-size rectangle
|
|
35
|
-
* for a controls overlay to anchor to. `<PlayerRoot>` renders it.
|
|
36
|
-
*
|
|
37
|
-
* Whether this component and `<PlayerRoot>` should exist at all is an
|
|
38
|
-
* open question — see `B-035` in the app's master plan. Until that is
|
|
39
|
-
* decided they stay: a published package cannot quietly drop a public
|
|
40
|
-
* export.
|
|
41
|
-
*/
|
|
42
|
-
export function PlayerSurface({
|
|
43
|
-
backgroundColor = 'transparent',
|
|
44
|
-
}: PlayerSurfaceProps): React.ReactElement {
|
|
45
|
-
return (
|
|
46
|
-
<View
|
|
47
|
-
style={[styles.surface, { backgroundColor }]}
|
|
48
|
-
accessibilityElementsHidden
|
|
49
|
-
importantForAccessibility="no-hide-descendants"
|
|
50
|
-
// Collapses any accessibility tree contribution from this
|
|
51
|
-
// placeholder; the SurfaceView on the native side is already
|
|
52
|
-
// hidden from a11y (Phase 4 sets `importantForAccessibility`
|
|
53
|
-
// to `no` on the MpvRenderView).
|
|
54
|
-
/>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const styles = StyleSheet.create({
|
|
59
|
-
surface: {
|
|
60
|
-
flex: 1,
|
|
61
|
-
},
|
|
62
|
-
});
|