@simba-dev/react-native-media-player 2.0.1 → 2.1.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/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/__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,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Regression tests: the PROGRESS context must not lose a field that the
|
|
3
|
-
* STATE context already holds.
|
|
4
|
-
*
|
|
5
|
-
* THE DEFECT (found on device, emulator-5554, 2026-10-20, lib 1.17.0):
|
|
6
|
-
*
|
|
7
|
-
* mpv delivers `duration` and `time-pos` inside ONE batch, ~3 ms apart
|
|
8
|
-
* (measured: `fileLoaded` 19:29:59.615, `time-pos` 19:29:59.616,
|
|
9
|
-
* `duration` 19:29:59.619). The provider handled each event with
|
|
10
|
-
* `applyPlayerEvent(stateRef.current, progressRef.current, ...)` and then
|
|
11
|
-
* wrote the two refs:
|
|
12
|
-
*
|
|
13
|
-
* - `stateRef.current` was written SYNCHRONOUSLY, in the event handler.
|
|
14
|
-
* - `progressRef.current` was written INSIDE the `setProgress` updater,
|
|
15
|
-
* which React DEFERS to the render phase.
|
|
16
|
-
*
|
|
17
|
-
* So the progress ref was one flush behind the state ref. The second event
|
|
18
|
-
* of the batch therefore computed its `nextProgress` from a STALE progress
|
|
19
|
-
* — one that did not yet contain the duration the first event had just
|
|
20
|
-
* delivered — and overwrote it with 0.
|
|
21
|
-
*
|
|
22
|
-
* MEASURED on device:
|
|
23
|
-
*
|
|
24
|
-
* state.durationMs = 7673792 (correct)
|
|
25
|
-
* progress.durationMs = 0 (WRONG)
|
|
26
|
-
*
|
|
27
|
-
* The visible damage was a seek bar with no played fill, NO buffered range
|
|
28
|
-
* at all (the consumer gates the buffered window on `durationMs > 0`), and
|
|
29
|
-
* "--:--" for the remaining time — on a video that was demonstrably
|
|
30
|
-
* playing.
|
|
31
|
-
*
|
|
32
|
-
* These tests pin the fix: the progress ref is written synchronously, in
|
|
33
|
-
* lockstep with the state ref.
|
|
34
|
-
*
|
|
35
|
-
* Test surface:
|
|
36
|
-
* - duration survives in the progress context when duration and position
|
|
37
|
-
* arrive in one batch (the exact device order)
|
|
38
|
-
* - duration survives when the order is reversed
|
|
39
|
-
* - duration survives across a longer run of interleaved events
|
|
40
|
-
* - the buffered ranges survive the same interleaving
|
|
41
|
-
* - the two contexts agree on the duration — the invariant the seek bar
|
|
42
|
-
* depends on
|
|
43
|
-
*
|
|
44
|
-
* The MpvPlayerModule bridge mock is installed globally in
|
|
45
|
-
* `jest.setup.ts`; its `getDuration` returns 0, so the hydrated baseline
|
|
46
|
-
* duration is 0 and every value asserted here arrives through the EVENT
|
|
47
|
-
* path. A test that passed on the hydrated baseline would prove nothing.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
import React from 'react';
|
|
51
|
-
import { act, renderHook } from '@testing-library/react-native';
|
|
52
|
-
import { PlayerProvider } from '../PlayerProvider';
|
|
53
|
-
import { usePlayer, usePlayerProgress } from '../../types/player';
|
|
54
|
-
|
|
55
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
56
|
-
<PlayerProvider>{children}</PlayerProvider>
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Deliver an event through the SAME emitter production uses.
|
|
61
|
-
*
|
|
62
|
-
* The bridge's `resolveEmitter()` builds a `NativeEventEmitter` over
|
|
63
|
-
* `NativeModules.MpvPlayerModule`, and on the native side the events are
|
|
64
|
-
* published through `RCTDeviceEventEmitter`. RN's own jest preset mocks
|
|
65
|
-
* `DeviceEventEmitter`, and `NativeEventEmitter` delegates to it, so
|
|
66
|
-
* emitting there drives the real subscription the provider registered.
|
|
67
|
-
*/
|
|
68
|
-
function emit(eventName: string, payload: Record<string, unknown>): void {
|
|
69
|
-
const {
|
|
70
|
-
DeviceEventEmitter,
|
|
71
|
-
} = require('react-native') as typeof import('react-native');
|
|
72
|
-
DeviceEventEmitter.emit(eventName, payload);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** The real movie length from the device session: 7673.792 seconds. */
|
|
76
|
-
const DURATION_S = 7673.792;
|
|
77
|
-
const DURATION_MS = 7673792;
|
|
78
|
-
|
|
79
|
-
describe('PlayerProvider progress context keeps the duration', () => {
|
|
80
|
-
it('keeps the duration when duration and position arrive in ONE batch', async () => {
|
|
81
|
-
// The exact device scenario: two events, one batch, duration FIRST.
|
|
82
|
-
const { result, unmount } = await renderHook(
|
|
83
|
-
() => ({ state: usePlayer().state, progress: usePlayerProgress() }),
|
|
84
|
-
{ wrapper },
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
// The hydrated baseline is 0 (the bridge mock's getDuration returns 0),
|
|
88
|
-
// so anything asserted below arrived through the event path.
|
|
89
|
-
expect(result.current.state.durationMs).toBe(0);
|
|
90
|
-
expect(result.current.progress.durationMs).toBe(0);
|
|
91
|
-
|
|
92
|
-
await act(async () => {
|
|
93
|
-
emit('onDurationChanged', { duration: DURATION_S });
|
|
94
|
-
emit('onPositionChanged', { position: 12.5 });
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(result.current.state.durationMs).toBe(DURATION_MS);
|
|
98
|
-
// THE assertion this file exists for. Before the fix this was 0:
|
|
99
|
-
// the position event was computed from a stale progress and replaced
|
|
100
|
-
// the duration with the stale 0.
|
|
101
|
-
expect(result.current.progress.durationMs).toBe(DURATION_MS);
|
|
102
|
-
// The position must not be the casualty of the fix.
|
|
103
|
-
expect(result.current.progress.positionMs).toBe(12500);
|
|
104
|
-
|
|
105
|
-
await unmount();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('keeps the duration when the position arrives FIRST in the batch', async () => {
|
|
109
|
-
// The mirror order. A fix that only special-cased "duration first"
|
|
110
|
-
// would pass the test above and fail this one.
|
|
111
|
-
const { result, unmount } = await renderHook(
|
|
112
|
-
() => ({ state: usePlayer().state, progress: usePlayerProgress() }),
|
|
113
|
-
{ wrapper },
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
await act(async () => {
|
|
117
|
-
emit('onPositionChanged', { position: 12.5 });
|
|
118
|
-
emit('onDurationChanged', { duration: DURATION_S });
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
expect(result.current.progress.durationMs).toBe(DURATION_MS);
|
|
122
|
-
expect(result.current.progress.positionMs).toBe(12500);
|
|
123
|
-
|
|
124
|
-
await unmount();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('keeps the duration across a long run of interleaved events', async () => {
|
|
128
|
-
// The real event stream is not two events: mpv keeps sending
|
|
129
|
-
// `time-pos` for the whole session. Every one of them used to carry a
|
|
130
|
-
// stale duration into the progress context.
|
|
131
|
-
const { result, unmount } = await renderHook(
|
|
132
|
-
() => ({ state: usePlayer().state, progress: usePlayerProgress() }),
|
|
133
|
-
{ wrapper },
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
await act(async () => {
|
|
137
|
-
emit('onDurationChanged', { duration: DURATION_S });
|
|
138
|
-
for (let i = 1; i <= 25; i++) {
|
|
139
|
-
emit('onPositionChanged', { position: i * 0.5 });
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
expect(result.current.progress.durationMs).toBe(DURATION_MS);
|
|
144
|
-
expect(result.current.progress.positionMs).toBe(12500);
|
|
145
|
-
|
|
146
|
-
await unmount();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('keeps the buffered ranges through the same interleaving', async () => {
|
|
150
|
-
// The buffered ranges are the other half of the damage: the consumer
|
|
151
|
-
// gates the buffered window on `durationMs > 0`, so a lost duration
|
|
152
|
-
// silently removed the buffered indicator from the seek bar.
|
|
153
|
-
const { result, unmount } = await renderHook(
|
|
154
|
-
() => ({ state: usePlayer().state, progress: usePlayerProgress() }),
|
|
155
|
-
{ wrapper },
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
await act(async () => {
|
|
159
|
-
emit('onDurationChanged', { duration: DURATION_S });
|
|
160
|
-
emit('onCacheState', { ranges: [{ start: 0, end: 130713.917 }] });
|
|
161
|
-
emit('onPositionChanged', { position: 12.5 });
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
expect(result.current.progress.durationMs).toBe(DURATION_MS);
|
|
165
|
-
expect(result.current.progress.cacheRanges).toEqual([
|
|
166
|
-
{ start: 0, end: 130713.917 },
|
|
167
|
-
]);
|
|
168
|
-
|
|
169
|
-
await unmount();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('keeps the state context and the progress context in agreement', async () => {
|
|
173
|
-
// The invariant the seek bar depends on: it reads the duration from
|
|
174
|
-
// the progress context and the play state from the state context, so
|
|
175
|
-
// the two must never disagree about the length of the file.
|
|
176
|
-
const { result, unmount } = await renderHook(
|
|
177
|
-
() => ({ state: usePlayer().state, progress: usePlayerProgress() }),
|
|
178
|
-
{ wrapper },
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
await act(async () => {
|
|
182
|
-
emit('onDurationChanged', { duration: DURATION_S });
|
|
183
|
-
emit('onPositionChanged', { position: 12.5 });
|
|
184
|
-
emit('onCacheState', { ranges: [{ start: 0, end: 130713.917 }] });
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(result.current.progress.durationMs).toBe(
|
|
188
|
-
result.current.state.durationMs,
|
|
189
|
-
);
|
|
190
|
-
expect(result.current.progress.durationMs).toBe(DURATION_MS);
|
|
191
|
-
|
|
192
|
-
await unmount();
|
|
193
|
-
});
|
|
194
|
-
});
|