@simba-dev/react-native-media-player 1.13.6 → 1.13.8
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.
|
@@ -6,6 +6,7 @@ import android.view.Gravity
|
|
|
6
6
|
import android.view.SurfaceHolder
|
|
7
7
|
import android.view.SurfaceView
|
|
8
8
|
import android.view.View
|
|
9
|
+
import android.view.ViewGroup
|
|
9
10
|
import android.widget.FrameLayout
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -99,8 +100,21 @@ class MpvRenderView(context: Context) : SurfaceView(context),
|
|
|
99
100
|
// This is the same mechanism the audio mini bar already relies on.
|
|
100
101
|
|
|
101
102
|
/**
|
|
102
|
-
* Place the surface at an absolute rect, in pixels, inside the
|
|
103
|
-
*
|
|
103
|
+
* Place the surface at an absolute rect, in **window** pixels, inside the
|
|
104
|
+
* host window. Used by the in-app mini player.
|
|
105
|
+
*
|
|
106
|
+
* The coordinates are window-relative on purpose. The only thing that
|
|
107
|
+
* knows a view's window rect is the platform, and RN's
|
|
108
|
+
* `measureInWindow` is the JS-side equivalent of the same space — so
|
|
109
|
+
* accepting window pixels makes "measure a view, hand the result over"
|
|
110
|
+
* a straight pass-through with no coordinate-system translation in the
|
|
111
|
+
* middle. The alternative (content-relative margins) looks simpler but
|
|
112
|
+
* silently disagrees with JS by the window inset, which is zero under
|
|
113
|
+
* edge-to-edge and non-zero the moment that is not — a video that lands
|
|
114
|
+
* offset inside its dock, with nothing in the logs.
|
|
115
|
+
*
|
|
116
|
+
* The conversion to content-relative margins happens here, where the
|
|
117
|
+
* container's own window offset is available and exact.
|
|
104
118
|
*
|
|
105
119
|
* Refuses non-positive extents rather than clamping: a zero-sized
|
|
106
120
|
* SurfaceView is an invalid target for libmpv, and silently substituting
|
|
@@ -112,14 +126,27 @@ class MpvRenderView(context: Context) : SurfaceView(context),
|
|
|
112
126
|
Log.w(TAG, "setVideoBounds refused ${width}x$height at ($x,$y): extents must be > 0")
|
|
113
127
|
return
|
|
114
128
|
}
|
|
129
|
+
val parent = parent as? ViewGroup
|
|
130
|
+
if (parent == null) {
|
|
131
|
+
Log.w(TAG, "setVideoBounds refused: the surface has no container to position within")
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
// Where the container itself starts in window coordinates. Subtracting
|
|
135
|
+
// it turns the caller's window rect into the margin the container
|
|
136
|
+
// expects.
|
|
137
|
+
val containerOffset = IntArray(2)
|
|
138
|
+
parent.getLocationInWindow(containerOffset)
|
|
139
|
+
val left = x - containerOffset[0]
|
|
140
|
+
val top = y - containerOffset[1]
|
|
141
|
+
|
|
115
142
|
val lp = frameParams()
|
|
116
143
|
lp.width = width
|
|
117
144
|
lp.height = height
|
|
118
145
|
lp.gravity = Gravity.TOP or Gravity.START
|
|
119
|
-
lp.leftMargin =
|
|
120
|
-
lp.topMargin =
|
|
146
|
+
lp.leftMargin = left
|
|
147
|
+
lp.topMargin = top
|
|
121
148
|
layoutParams = lp
|
|
122
|
-
Log.i(TAG, "setVideoBounds -> ${width}x$height at ($x,$y)")
|
|
149
|
+
Log.i(TAG, "setVideoBounds -> ${width}x$height at window($x,$y) = margin($left,$top)")
|
|
123
150
|
}
|
|
124
151
|
|
|
125
152
|
/** Expand the surface to fill the host container. */
|
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.8",
|
|
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. */
|
|
@@ -419,7 +436,7 @@ export interface MpvPlayerModuleBridge {
|
|
|
419
436
|
isAudioPlaybackServiceRunning(): boolean;
|
|
420
437
|
|
|
421
438
|
/**
|
|
422
|
-
* Resize the video surface to an absolute rect
|
|
439
|
+
* Resize the video surface to an absolute rect, in **window** pixels.
|
|
423
440
|
*
|
|
424
441
|
* V21 places the player in the consumer app's single Activity, where the
|
|
425
442
|
* one surface renders both fullscreen and the in-app mini player's live
|
|
@@ -427,6 +444,14 @@ export interface MpvPlayerModuleBridge {
|
|
|
427
444
|
* remounts the view, so the Surface is not destroyed and mpv does not
|
|
428
445
|
* re-attach.
|
|
429
446
|
*
|
|
447
|
+
* The coordinates are window-relative so a caller can pass straight
|
|
448
|
+
* through what React Native's `measureInWindow` returned, with no
|
|
449
|
+
* coordinate-system translation in the middle. Converting to
|
|
450
|
+
* content-relative margins is the native side's job: it is the only side
|
|
451
|
+
* that knows the window inset, and it is zero under edge-to-edge and
|
|
452
|
+
* non-zero otherwise, so a translation done in JS would be right exactly
|
|
453
|
+
* once and silently wrong after any change to the window setup.
|
|
454
|
+
*
|
|
430
455
|
* Resolves `false` when there is no surface, when the call arrives off the
|
|
431
456
|
* main thread, or when the extents are non-positive. A caller that gets
|
|
432
457
|
* `false` must not present the video as shown.
|
|
@@ -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) {
|