@simba-dev/react-native-media-player 1.13.7 → 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 host
103
- * container. Used by the in-app mini player.
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 = x
120
- lp.topMargin = y
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.7",
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",
@@ -436,7 +436,7 @@ export interface MpvPlayerModuleBridge {
436
436
  isAudioPlaybackServiceRunning(): boolean;
437
437
 
438
438
  /**
439
- * Resize the video surface to an absolute rect inside its container.
439
+ * Resize the video surface to an absolute rect, in **window** pixels.
440
440
  *
441
441
  * V21 places the player in the consumer app's single Activity, where the
442
442
  * one surface renders both fullscreen and the in-app mini player's live
@@ -444,6 +444,14 @@ export interface MpvPlayerModuleBridge {
444
444
  * remounts the view, so the Surface is not destroyed and mpv does not
445
445
  * re-attach.
446
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
+ *
447
455
  * Resolves `false` when there is no surface, when the call arrives off the
448
456
  * main thread, or when the extents are non-positive. A caller that gets
449
457
  * `false` must not present the video as shown.