@simba-dev/react-native-media-player 1.13.5 → 1.13.6
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.
|
@@ -123,6 +123,15 @@ object PipManager {
|
|
|
123
123
|
.setAspectRatio(aspectRational)
|
|
124
124
|
.setActions(actions)
|
|
125
125
|
|
|
126
|
+
// Seamless resize (Android 12+). Without it the PiP window animates
|
|
127
|
+
// between two discrete sizes on rotation / return, which reads as a
|
|
128
|
+
// stutter rather than a resize. This is a rendering-quality flag only:
|
|
129
|
+
// it changes how the transition is drawn, never whether PiP is
|
|
130
|
+
// entered, so it carries no behavioural risk.
|
|
131
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
132
|
+
builder.setSeamlessResizeEnabled(true)
|
|
133
|
+
}
|
|
134
|
+
|
|
126
135
|
// Source rect hint for smooth entry animation (Android 12+)
|
|
127
136
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && sourceRectHint != null) {
|
|
128
137
|
builder.setSourceRectHint(sourceRectHint)
|
|
@@ -2373,10 +2373,45 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2373
2373
|
// rather than blank.
|
|
2374
2374
|
val title = chapterTitle?.takeIf { it.isNotBlank() } ?: "Simba Player"
|
|
2375
2375
|
val pct = progressPct?.takeIf { it.isNotBlank() } ?: "0 %"
|
|
2376
|
+
// The PiP window's shape is the loaded video's shape. This used to
|
|
2377
|
+
// take the `16f / 9f` default from buildPipParams, so every PiP
|
|
2378
|
+
// window was 16:9 no matter what was playing -- a 4:3 archive or a
|
|
2379
|
+
// 2.35:1 scope film was letterboxed into the wrong window, and the
|
|
2380
|
+
// mismatch was baked in at entry so the system animated to a shape
|
|
2381
|
+
// that did not match the picture inside it.
|
|
2382
|
+
//
|
|
2383
|
+
// Read from the same `width` / `height` properties `getVideoParams`
|
|
2384
|
+
// already reads, rather than adding a second, parallel way to ask
|
|
2385
|
+
// mpv about dimensions.
|
|
2386
|
+
val aspect = currentVideoAspect()
|
|
2387
|
+
if (aspect == null) {
|
|
2388
|
+
Log.w(
|
|
2389
|
+
TAG,
|
|
2390
|
+
"[PlaybackTrace][Bridge][enterPip] no video dimensions loaded " +
|
|
2391
|
+
"(no file, or audio-only); PiP window will use 16:9",
|
|
2392
|
+
)
|
|
2393
|
+
}
|
|
2394
|
+
// Source rect hint: where the video actually is right now, in window
|
|
2395
|
+
// coordinates. This is what makes PiP entry animate the real frame into
|
|
2396
|
+
// the window instead of growing out of a black rectangle.
|
|
2397
|
+
//
|
|
2398
|
+
// The hint's shape has to match the aspect ratio above, or the system
|
|
2399
|
+
// scales the frame non-proportionally to fit and the video visibly
|
|
2400
|
+
// arrives stretched. Both come from the same place -- the surface is
|
|
2401
|
+
// sized with the video's own shape by `setVideoBounds` / `fillBounds`,
|
|
2402
|
+
// and `boundsInWindow()` reports that same surface -- so they agree by
|
|
2403
|
+
// construction instead of being kept in sync by hand.
|
|
2404
|
+
//
|
|
2405
|
+
// Null when the surface is hidden or zero-sized: no video rect to
|
|
2406
|
+
// animate from. That degrades to the no-hint behaviour, which costs a
|
|
2407
|
+
// black transition but never a distorted one.
|
|
2408
|
+
val sourceRect = PlayerSurface.boundsInWindow()
|
|
2376
2409
|
try {
|
|
2377
2410
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
2378
2411
|
val pipParams = com.simba.player.PipManager.buildPipParams(
|
|
2379
2412
|
context = activity,
|
|
2413
|
+
aspect = aspect ?: (16f / 9f),
|
|
2414
|
+
sourceRectHint = sourceRect,
|
|
2380
2415
|
chapterTitle = title,
|
|
2381
2416
|
progressPercentage = pct,
|
|
2382
2417
|
)
|
|
@@ -2400,6 +2435,29 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2400
2435
|
* Exit PiP mode by bringing the activity to the front.
|
|
2401
2436
|
* Called from JS when user taps "Expand" in PiP RemoteActions.
|
|
2402
2437
|
*/
|
|
2438
|
+
/**
|
|
2439
|
+
* Display aspect (width / height) of the loaded video, or `null` when it
|
|
2440
|
+
* is not known.
|
|
2441
|
+
*
|
|
2442
|
+
* Reads the same `width` / `height` properties as [getVideoParams]. Null
|
|
2443
|
+
* is the honest answer for "no file loaded" and for "audio only" -- both
|
|
2444
|
+
* are real, expected states rather than failures -- and callers decide
|
|
2445
|
+
* what a shape-less PiP window means for them.
|
|
2446
|
+
*/
|
|
2447
|
+
private fun currentVideoAspect(): Float? {
|
|
2448
|
+
val ptr = nativePtr
|
|
2449
|
+
if (ptr == 0L) return null
|
|
2450
|
+
return try {
|
|
2451
|
+
val w = MPVLib.nativeGetProperty(ptr, "width").trim().trim('"').toDoubleOrNull()
|
|
2452
|
+
val h = MPVLib.nativeGetProperty(ptr, "height").trim().trim('"').toDoubleOrNull()
|
|
2453
|
+
if (w != null && h != null && w > 0.0 && h > 0.0) (w / h).toFloat() else null
|
|
2454
|
+
} catch (e: Exception) {
|
|
2455
|
+
// The native lease guard refuses reads against a destroyed engine.
|
|
2456
|
+
Log.w(TAG, "[PlaybackTrace][Bridge][currentVideoAspect] ${e.message}")
|
|
2457
|
+
null
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2403
2461
|
@ReactMethod
|
|
2404
2462
|
@Override
|
|
2405
2463
|
override fun exitPip() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.simba.player.mpv
|
|
2
2
|
|
|
3
3
|
import android.app.Activity
|
|
4
|
+
import android.graphics.Rect
|
|
4
5
|
import android.os.Looper
|
|
5
6
|
import android.util.Log
|
|
6
7
|
import android.view.View
|
|
@@ -185,6 +186,46 @@ object PlayerSurface {
|
|
|
185
186
|
fun setVisible(visible: Boolean): Boolean =
|
|
186
187
|
withSurface("setVisible") { it.setSurfaceVisible(visible) }
|
|
187
188
|
|
|
189
|
+
/**
|
|
190
|
+
* The surface's current rect in window coordinates, or `null` when it has
|
|
191
|
+
* no on-screen area.
|
|
192
|
+
*
|
|
193
|
+
* This is the `setSourceRectHint` Android wants at PiP entry. With it the
|
|
194
|
+
* system animates the real video frame into the PiP window; without it the
|
|
195
|
+
* window grows out of a black rectangle.
|
|
196
|
+
*
|
|
197
|
+
* The hint must describe a rect of the *same shape* as the PiP aspect
|
|
198
|
+
* ratio, or the system scales the frame non-proportionally to fit and the
|
|
199
|
+
* video visibly arrives stretched or squashed. Because this rect is the
|
|
200
|
+
* surface itself and the surface is sized by [setBounds] / [fillBounds]
|
|
201
|
+
* with the video's own shape, the two agree by construction rather than by
|
|
202
|
+
* being kept in sync by hand.
|
|
203
|
+
*
|
|
204
|
+
* `null` is the honest answer while the surface is `GONE` or zero-sized --
|
|
205
|
+
* there is no video rect to animate from, and returning a zero rect would
|
|
206
|
+
* ask the system to animate from nothing. Null degrades to the no-hint
|
|
207
|
+
* behaviour, which costs a black transition but never a distorted one.
|
|
208
|
+
*/
|
|
209
|
+
@JvmStatic
|
|
210
|
+
fun boundsInWindow(): Rect? {
|
|
211
|
+
if (Looper.myLooper() != Looper.getMainLooper()) {
|
|
212
|
+
Log.e(TAG, "boundsInWindow refused: must be called from the main thread")
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
val view = viewRef.get() ?: return null
|
|
216
|
+
if (view.visibility != View.VISIBLE || view.width <= 0 || view.height <= 0) {
|
|
217
|
+
return null
|
|
218
|
+
}
|
|
219
|
+
val location = IntArray(2)
|
|
220
|
+
view.getLocationInWindow(location)
|
|
221
|
+
return Rect(
|
|
222
|
+
location[0],
|
|
223
|
+
location[1],
|
|
224
|
+
location[0] + view.width,
|
|
225
|
+
location[1] + view.height,
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
188
229
|
/**
|
|
189
230
|
* Run [block] against the surface on the main thread.
|
|
190
231
|
*
|
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.6",
|
|
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",
|