@simba-dev/react-native-media-player 1.13.6 → 1.13.7
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.7",
|
|
4
4
|
"description": "React Native video & audio player powered by libmpv — Picture-in-Picture, MediaSession, foreground service, and a customizable TypeScript UI. Built for Android. Designed as a drop-in replacement for react-native-video / react-native-track-player / expo-av. See CHANGELOG.md for per-version notes.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -86,6 +86,23 @@ export interface LaunchParams {
|
|
|
86
86
|
readonly title: string;
|
|
87
87
|
readonly type: 'video' | 'audio';
|
|
88
88
|
readonly startPositionMs: number;
|
|
89
|
+
/**
|
|
90
|
+
* Monotonic identity of one launch request. Optional.
|
|
91
|
+
*
|
|
92
|
+
* `uri` + `startPositionMs` is not a unique identity for a launch, and
|
|
93
|
+
* `useLaunchPlayback` keys its load effect on exactly that pair. That was
|
|
94
|
+
* sound while every launch started a fresh `PlayerActivity` — a new React
|
|
95
|
+
* root, so the hook mounted fresh and always fired.
|
|
96
|
+
*
|
|
97
|
+
* It stops being sound the moment playback is loaded into an already-open
|
|
98
|
+
* window: the hook stays mounted across launches, so backing out of a film
|
|
99
|
+
* and tapping it again produces the same key and no second load happens.
|
|
100
|
+
* The user presses play and nothing occurs.
|
|
101
|
+
*
|
|
102
|
+
* A caller that loads in-window should therefore supply this. It matches
|
|
103
|
+
* `loadFileWithRequestId`, which already exists for the same reason.
|
|
104
|
+
*/
|
|
105
|
+
readonly requestId?: string;
|
|
89
106
|
}
|
|
90
107
|
|
|
91
108
|
/** All 22 events emitted by the Kotlin bridge. */
|
|
@@ -95,6 +95,41 @@ describe('useLaunchPlayback', () => {
|
|
|
95
95
|
);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
// ── requestId: re-launching the SAME media must load again ───────────
|
|
99
|
+
//
|
|
100
|
+
// `uri` + `startPositionMs` is not a unique identity for a launch. It was
|
|
101
|
+
// sound only because every launch used to start a fresh `PlayerActivity` —
|
|
102
|
+
// a new React root, so this hook mounted fresh and always fired.
|
|
103
|
+
//
|
|
104
|
+
// The moment playback is loaded into an already-open window, this hook
|
|
105
|
+
// stays mounted across launches and that guarantee disappears. The
|
|
106
|
+
// everyday action that breaks is "back out of a film, tap it again": same
|
|
107
|
+
// URI, resume policy hands back the same position, same key, no load, and
|
|
108
|
+
// the user presses play and nothing happens.
|
|
109
|
+
|
|
110
|
+
it('loads again for the SAME uri and position when requestId differs', async () => {
|
|
111
|
+
const {rerender} = await render(
|
|
112
|
+
<Harness params={{...PARAMS, requestId: 'session-1'}} />,
|
|
113
|
+
);
|
|
114
|
+
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
115
|
+
|
|
116
|
+
await rerender(<Harness params={{...PARAMS, requestId: 'session-2'}} />);
|
|
117
|
+
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(2));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('does NOT re-fire when requestId is present but unchanged', async () => {
|
|
121
|
+
// The 1 Hz position poll still re-renders consumers constantly; a new
|
|
122
|
+
// object literal for the same launch must not reload.
|
|
123
|
+
const {rerender} = await render(
|
|
124
|
+
<Harness params={{...PARAMS, requestId: 'session-1'}} />,
|
|
125
|
+
);
|
|
126
|
+
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
127
|
+
|
|
128
|
+
await rerender(<Harness params={{...PARAMS, requestId: 'session-1'}} />);
|
|
129
|
+
await rerender(<Harness params={{...PARAMS, requestId: 'session-1'}} />);
|
|
130
|
+
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
131
|
+
});
|
|
132
|
+
|
|
98
133
|
it('converts startPositionMs from milliseconds to seconds', async () => {
|
|
99
134
|
render(<Harness params={{...PARAMS, startPositionMs: 90_000}} />);
|
|
100
135
|
await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
|
|
@@ -52,7 +52,17 @@ export function useLaunchPlayback(
|
|
|
52
52
|
const startPositionSec = launchParams?.startPositionMs
|
|
53
53
|
? launchParams.startPositionMs / 1000
|
|
54
54
|
: 0;
|
|
55
|
-
|
|
55
|
+
// A caller-supplied `requestId` ADDS launch identity to the key; it does
|
|
56
|
+
// not replace the uri|position part. Without it the key was `uri|position`,
|
|
57
|
+
// which is not unique across launches: that was only ever sound because
|
|
58
|
+
// each launch used to start a fresh Activity (fresh React root → fresh
|
|
59
|
+
// mount → always fires). A consumer that loads into an already-open window
|
|
60
|
+
// keeps this hook mounted, so re-launching the same file at the same
|
|
61
|
+
// position would produce the same key, skip the load, and the user would
|
|
62
|
+
// press play and see nothing.
|
|
63
|
+
const requestId = launchParams?.requestId;
|
|
64
|
+
const launchKey =
|
|
65
|
+
uri == null ? null : `${requestId ?? ''}|${uri}|${startPositionSec}`;
|
|
56
66
|
|
|
57
67
|
useEffect(() => {
|
|
58
68
|
if (launchKey == null || uri == null) {
|