@simba-dev/react-native-media-player 3.3.3 → 3.3.4

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/CHANGELOG.md CHANGED
@@ -1,4 +1,60 @@
1
1
 
2
+ ## [3.3.4] - 2026-11-06
3
+
4
+ ### Fixed
5
+
6
+ - **The HOME path opened NO Picture-in-Picture window at all.** This is a regression the 3.3.3
7
+ release shipped, and it is the reason this release exists. Measured on emulator-5554 (API 37) on
8
+ 2026-11-05, and again on 2026-11-06, on the 3.3.3 build:
9
+
10
+ ```
11
+ 15:21:28.392 onPictureInPictureRequested: the platform asked the app to enter PiP
12
+ 15:21:28.423 hideConsumerChrome: hid the chrome view ... visibility=8
13
+ 15:21:28.826 the PiP entry is scheduled for the next draw
14
+ 15:21:29.139 onUserLeaveHint: the user is leaving the app
15
+ 15:21:30.186 askForTheWindow: the OS refused the PiP entry
16
+ ```
17
+
18
+ `dumpsys activity activities` reported `mLastReportedPictureInPictureMode=false` — the entry
19
+ never happened. The cause is measured: 3.3.3 deferred the OS ask to the window's next draw, the
20
+ ask landed **1.8 s** after the platform's request, and by then the Activity had been paused.
21
+ `Activity.enterPictureInPictureMode` throws unless the Activity is RESUMED, so the OS refused
22
+ the entry.
23
+
24
+ **The fix:** the ask is synchronous again — inside `onPictureInPictureRequested()`, in that
25
+ tick, on every API level. The chrome is still hidden before the ask, and the params are still
26
+ committed before it.
27
+
28
+ ### Retracted
29
+
30
+ - **"The hide has to be DRAWN before the platform takes the window."** (3.3.3) That claim was
31
+ **never proven**. It rested on a single measurement — the window's draw counter did not move
32
+ between the hide and the entry — which is consistent with a stale frame AND with a draw that had
33
+ not been scheduled yet. A single screenshot cannot separate the two, and the release stated the
34
+ inference as a measured cause.
35
+
36
+ The mechanism built on that claim — a draw-gated entry on the API 31+ path, waiting for a
37
+ `ViewTreeObserver.OnDrawListener` — is removed here, in the same release that withdraws the
38
+ claim. The 3.3.3 CHANGELOG entry below still quotes the old wording on purpose: a retraction
39
+ that deletes the wrong text is not a retraction.
40
+
41
+ - **"A PiP window that still carries the chrome is better than no PiP window at all."** (3.3.3)
42
+ That was the decision behind the bounded wait, and it was wrong in practice: the wait did not
43
+ produce a PiP window with the chrome, it produced **no PiP window at all**. The entry is worth
44
+ more than the cosmetics.
45
+
46
+ - **"It returns whether the entry was started — on API 31+ that means it was scheduled for the
47
+ next draw."** (README) The entry is no longer scheduled for anything. The return value is the
48
+ OS's answer again: `true` when the Activity entered Picture-in-Picture, `false` when it was
49
+ refused.
50
+
51
+ ### Not claimed
52
+
53
+ - Whether the PiP window shows the app's chrome is **not** settled by this release. The hide is
54
+ applied natively before the entry, and on a playing video the PiP window comes up video-only; on
55
+ a paused video it has been seen carrying the app's full expanded chrome. The mechanism behind
56
+ that difference is still open, and it is measured per release rather than assumed.
57
+
2
58
  ## [3.3.3] - 2026-11-05
3
59
 
4
60
  ### Fixed
package/README.md CHANGED
@@ -387,9 +387,8 @@ path. The same library call serves both, so there is one entry and one owner. Wh
387
387
  hook matters is in [Why it is native](#why-it-is-native-and-why-your-activity-hands-over-the-activity).
388
388
 
389
389
  The library then hides your chrome, asks the OS for the window, and brings your chrome back when
390
- Picture-in-Picture ends. It returns whether the entry was **started** — on API 31+ that means it
391
- was scheduled for the next draw, because the chrome-less frame has to be on the screen before the
392
- platform takes the window — and `false` when the entry was refused, so you can log it:
390
+ Picture-in-Picture ends. It returns whether the OS **accepted** the entry, and `false` when the
391
+ entry was refused, so you can log it:
393
392
 
394
393
  ```kotlin
395
394
  val entered = com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint(this)
@@ -419,10 +418,11 @@ your Activity is still **RESUMED**. That matters twice over:
419
418
 
420
419
  - `Activity.enterPictureInPictureMode()` throws `IllegalStateException` unless the Activity is
421
420
  resumed, so this is the only moment an explicit entry is legal at all.
422
- - the Activity is still **RESUMED** for a few hundred milliseconds after this hook, and that is
423
- the window the library uses to draw the chrome-less frame before it asks for the PiP window.
424
- Measured on emulator-5554 (API 37) on 2026-11-05: `onPictureInPictureRequested` at `33.942`,
425
- `onUserLeaveHint` at `34.300` — 358 ms of RESUMED time.
421
+ - the Activity is still **RESUMED** for a few hundred milliseconds after this hook, but the
422
+ library does NOT spend that window waiting: the OS ask happens **inside** this callback, in
423
+ this tick. Measured on emulator-5554 (API 37) on 2026-11-05 and again on 2026-11-06, an ask
424
+ deferred past the callback landed 1.8 s later, by which time the Activity had been paused, and
425
+ the OS **refused** the entry — so no PiP window opened at all.
426
426
 
427
427
  That is why the library does **not** arm the platform's auto-enter switch: with it armed there
428
428
  is no pre-transition hook to use.
@@ -441,23 +441,20 @@ Three things have to be right for that to work:
441
441
  2. **The entry happens while your Activity is resumed.** On API 31+ that means
442
442
  `onPictureInPictureRequested()`; see
443
443
  [Why it is native](#why-it-is-native-and-why-your-activity-hands-over-the-activity).
444
- 3. **The hide has to be DRAWN.** This is the one that is easy to get wrong, and it was measured:
445
- on API 31+ the library hides your chrome root and then asks the OS for the window — and the
446
- window showed the app's full expanded chrome anyway. The reason is that
447
- `View.setVisibility(GONE)` only **schedules** a traversal: in that run the window's draw
448
- counter did not move at all between the hide and the entry, so the hide never reached the
449
- pixels. The PiP window's UI layer is the app's **last drawn frame** — the video keeps playing
450
- inside it because the video is a `SurfaceView`, a separate layer the platform re-parents —
451
- so a frame that was never drawn cannot be in it.
452
-
453
- The library therefore forces the window to schedule a draw that carries the hidden chrome
454
- (`invalidate()` + `requestLayout()`) and asks the OS for the window **from that draw**. If the
455
- window never draws, the entry goes on anyway after a bounded wait: a PiP window that still
456
- carries your chrome is better than no PiP window at all.
457
-
458
- You can reproduce the defect without that fix: pause the video, so the app has nothing to
459
- animate and stops drawing, and then press HOME. With the video playing, the same press gives
460
- a clean, video-only PiP window.
444
+ 3. **Whether that hide is enough is MEASURED, not assumed.** The library hides your chrome root
445
+ and then asks the OS for the window in the same tick. On a playing video the PiP window comes
446
+ up video-only. On a **paused** video the PiP window has been seen carrying the app's full
447
+ expanded chrome.
448
+
449
+ The 3.3.3 release claimed to know why: that `View.setVisibility(GONE)` only *schedules* a
450
+ traversal, so the hide never reached the pixels, and the PiP window therefore showed the app's
451
+ **last drawn frame**. It built a draw-gated entry on that claim — and **the claim was never
452
+ proven**, and the mechanism broke the entry outright (see the retraction below). The honest
453
+ statement today is the narrower one: the hide is applied natively, before the entry, and
454
+ whether the window that results is clean depends on the app still drawing.
455
+
456
+ If your app's PiP window shows your chrome, the first thing to check is whether the app is
457
+ still drawing at the moment of the entry.
461
458
 
462
459
  `PictureInPictureParams.setSourceRectHint(...)` is **not** part of this. It is a TRANSITION
463
460
  hint: it tells the platform which region of your window the PiP window should animate FROM. It
@@ -621,9 +618,8 @@ on leave does nothing, the Activity is not calling `MpvBridgeModule.notifyUserLe
621
618
  from `onPictureInPictureRequested()` (API 31+) or from `onUserLeaveHint()` (API 24-30) - see
622
619
  [Picture-in-Picture](#picture-in-picture).
623
620
 
624
- **The Picture-in-Picture window shows your app's chrome.** The chrome is hidden in the entry and
625
- that hide is **drawn** before the window is asked for — so the entry has to run while your Activity
626
- is resumed. On API
621
+ **The Picture-in-Picture window shows your app's chrome.** The chrome is hidden in the entry,
622
+ before the window is asked for — so the entry has to run while your Activity is resumed. On API
627
623
  31+ that means `onPictureInPictureRequested()` must return `true` and call the library:
628
624
  `onUserLeaveHint()` alone is **never called** there, because the platform's auto-enter switch
629
625
  transitions the window itself (measured: zero log lines on a HOME press). The library logs the
@@ -7,14 +7,12 @@ import android.graphics.Rect
7
7
  import android.media.MediaMetadataRetriever
8
8
  import android.util.Log
9
9
  import android.view.View
10
- import android.view.ViewTreeObserver
11
10
  import java.io.File
12
11
  import java.io.FileOutputStream
13
12
  import java.lang.ref.WeakReference
14
13
  import java.util.concurrent.ExecutorService
15
14
  import java.util.concurrent.Executors
16
15
  import java.util.concurrent.RejectedExecutionException
17
- import java.util.concurrent.atomic.AtomicBoolean
18
16
  import com.facebook.react.bridge.Arguments
19
17
  import com.facebook.react.bridge.Promise
20
18
  import com.facebook.react.bridge.ReadableArray
@@ -47,18 +45,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
47
45
  const val NAME = "MpvPlayerModule"
48
46
  private const val TAG = "MpvBridgeModule"
49
47
 
50
- /**
51
- * How long the native HOME entry waits for the window to DRAW the
52
- * chrome-less frame before it asks for the PiP window.
53
- *
54
- * Measured on emulator-5554 (API 37) on 2026-11-05: the platform
55
- * asked for PiP at `33.942` and the Activity was still RESUMED at
56
- * `34.300` — 358 ms of RESUMED time. The wait has to fit inside
57
- * that window, because `enterPictureInPictureMode` throws unless
58
- * the Activity is resumed.
59
- */
60
- private const val PIP_ENTRY_DRAW_TIMEOUT_MS = 250L
61
-
62
48
  // ── captureFrame: resume-rail thumbnails ──────────────────────────
63
49
  // `MediaMetadataRetriever` needs a real filesystem path for its
64
50
  // output. `filesDir` (NOT cacheDir) is deliberate: the platform
@@ -277,8 +263,14 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
277
263
  * 2026-11-04: with the hint committed, the PiP window showed the
278
264
  * app's full chrome, scaled down.
279
265
  *
280
- * The chrome is kept out by HIDING it before the entry — and by
281
- * having that hide DRAWN before the platform takes the window.
266
+ * The chrome is kept out by HIDING it before the entry.
267
+ *
268
+ * Whether that hide is SUFFICIENT — whether the PiP window still
269
+ * shows the chrome — is MEASURED per release, not assumed. The
270
+ * v3.3.3 release asserted that the hide had to be DRAWN before
271
+ * the platform took the window; that assertion was never proven,
272
+ * and the mechanism built on it broke the entry. See
273
+ * `notifyUserLeaveHint(activity)`.
282
274
  *
283
275
  * ## Why the restore still happens here
284
276
  *
@@ -492,110 +484,59 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
492
484
  *
493
485
  * @param activity the Activity that is leaving. It is the window
494
486
  * the PiP entry applies to.
495
- * @return `true` when the entry was STARTED — on API 31+ that
496
- * means it was scheduled for the next draw, because the
497
- * window must carry the chrome-less frame before the
498
- * platform takes it — and `false` when the entry was
499
- * refused.
500
- */
501
- /**
502
- * Ask for the PiP window — but only AFTER the window has DRAWN the
503
- * chrome-less frame.
504
- *
505
- * ## Why the entry waits for a draw
506
- *
507
- * Measured on emulator-5554 (API 37) on 2026-11-05, on the v3.3.1
508
- * build:
509
- *
510
- * - the native hide lands on the RIGHT view: the chrome root went
511
- * GONE and STAYED GONE — the same view identity before the hide
512
- * and after the mode change;
513
- * - and yet the PiP window showed the app's FULL expanded chrome,
514
- * scaled down, over the live video.
515
- *
516
- * The reason is measured, not guessed. `View.setVisibility(GONE)`
517
- * only SCHEDULES a traversal: in that run the window's draw counter
518
- * did NOT move between the hide and the entry, so the hide never
519
- * reached the pixels.
520
- *
521
- * The PiP window's UI layer is the app's last drawn frame. The
522
- * video keeps playing inside it because the video is a
523
- * `SurfaceView` — a separate layer the platform re-parents into
524
- * the PiP window — while the app's UI layer is a snapshot. A
525
- * snapshot taken before the chrome-less frame was drawn carries the
526
- * chrome.
527
- *
528
- * So: hide the chrome, FORCE the window to schedule a draw that
529
- * carries the hidden chrome, and ask for the window from that draw.
530
- *
531
- * ## The wait is BOUNDED
532
- *
533
- * If the window never draws, the entry goes on anyway: a PiP
534
- * window that still carries the chrome is better than no PiP
535
- * window at all. The bound is
536
- * [PIP_ENTRY_DRAW_TIMEOUT_MS], which fits inside the RESUMED window
537
- * the platform leaves before it pauses the Activity.
538
- */
539
- private fun enterPictureInPictureAfterDraw(activity: Activity): Boolean {
540
- val root = activity.window?.decorView
541
- if (root == null) {
542
- // No window to wait for: ask for the window now.
543
- return enterPictureInPicture(activity)
544
- }
545
- val observer = root.viewTreeObserver
546
- val asked = AtomicBoolean(false)
547
- val listener = object : ViewTreeObserver.OnDrawListener {
548
- override fun onDraw() {
549
- if (!asked.compareAndSet(false, true)) return
550
- removeDrawListener(observer, this)
551
- askForTheWindow(activity)
552
- }
553
- }
554
- // FORCE the window to schedule a draw that carries the hidden
555
- // chrome. The visibility change alone did not, and that is the
556
- // whole defect.
557
- root.invalidate()
558
- root.requestLayout()
559
- try {
560
- observer.addOnDrawListener(listener)
561
- } catch (e: IllegalStateException) {
562
- // The tree is not alive: there is nothing to wait for.
563
- return enterPictureInPicture(activity)
564
- }
565
- // The bound: a window that never draws must not hold the entry.
566
- root.postDelayed({
567
- if (asked.compareAndSet(false, true)) {
568
- removeDrawListener(observer, listener)
569
- askForTheWindow(activity)
570
- }
571
- }, PIP_ENTRY_DRAW_TIMEOUT_MS)
572
- return true
573
- }
574
-
575
- /**
576
- * Remove a draw listener without letting a dead view tree throw.
487
+ * @return `true` when the Activity entered Picture-in-Picture,
488
+ * `false` when the entry was refused.
577
489
  */
578
- private fun removeDrawListener(
579
- observer: ViewTreeObserver,
580
- listener: ViewTreeObserver.OnDrawListener,
581
- ) {
582
- try {
583
- observer.removeOnDrawListener(listener)
584
- } catch (e: IllegalStateException) {
585
- // The tree died with the window: there is nothing to remove.
586
- }
587
- }
588
-
589
490
  /**
590
- * The one call that asks the OS for the window, and the one place
591
- * the OS's answer is read.
491
+ * ## Why the window is asked for INSIDE the callback
492
+ *
493
+ * The ask is SYNCHRONOUS: it happens in this callback, in this
494
+ * tick, on every API level.
495
+ *
496
+ * Measured on emulator-5554 (API 37) on 2026-11-05, and again on
497
+ * 2026-11-06, on the v3.3.3 build — which DEFERRED the ask to the
498
+ * window's next draw:
499
+ *
500
+ * ```
501
+ * 15:21:28.392 onPictureInPictureRequested: the platform asked the app to enter PiP
502
+ * 15:21:28.423 hideConsumerChrome: hid the chrome view ... visibility=8
503
+ * 15:21:28.826 the PiP entry is scheduled for the next draw
504
+ * 15:21:29.139 onUserLeaveHint: the user is leaving the app
505
+ * 15:21:30.186 askForTheWindow: the OS refused the PiP entry
506
+ * ```
507
+ *
508
+ * The deferred ask landed 1.8 s after the platform's request —
509
+ * long after the Activity had been paused.
510
+ * `Activity.enterPictureInPictureMode` throws unless the Activity
511
+ * is RESUMED, so the OS refused the entry and **NO PiP window
512
+ * opened at all**. Both runs were identical, and
513
+ * `dumpsys activity activities` reported
514
+ * `mLastReportedPictureInPictureMode=false`.
515
+ *
516
+ * A PiP window that still carries the chrome is a defect. NO PiP
517
+ * window at all is worse, so the entry wins over the cosmetics.
518
+ *
519
+ * ## What v3.3.3 claimed, and why it is withdrawn
520
+ *
521
+ * v3.3.3 asserted that the chrome's hide had to be DRAWN before
522
+ * the platform took the window, and it gated the entry on a
523
+ * `ViewTreeObserver.OnDrawListener`. That claim was **never
524
+ * proven**. The one measurement it rested on — the window's draw
525
+ * counter did not move between the hide and the entry — is
526
+ * consistent with a stale frame AND with a draw that had not been
527
+ * scheduled yet, and a single screenshot cannot separate the two.
528
+ *
529
+ * The mechanism built on that claim broke the entry outright (see
530
+ * above). It is withdrawn here, in the same release that removes
531
+ * the code.
532
+ *
533
+ * ## What is still open
534
+ *
535
+ * Whether the PiP window shows the chrome is MEASURED, not
536
+ * assumed. The hide-before-ask is kept because it is the only
537
+ * ordering that can help and because it is harmless; whether it
538
+ * is SUFFICIENT is not settled by this file.
592
539
  */
593
- private fun askForTheWindow(activity: Activity) {
594
- if (!enterPictureInPicture(activity)) {
595
- Log.w(TAG, "companion.askForTheWindow: the OS refused the PiP entry")
596
- }
597
- }
598
-
599
540
  fun notifyUserLeaveHint(activity: Activity): Boolean {
600
541
  Log.i(
601
542
  TAG,
@@ -656,41 +597,27 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
656
597
  // region the PiP window ANIMATES FROM — a transition hint,
657
598
  // not a crop.
658
599
  commitPipParams(activity)
659
- // 6. Ask for the window — on API 31+ only AFTER the window has
660
- // DRAWN the chrome-less frame.
600
+ // 6. Ask for the window — SYNCHRONOUSLY, in this callback, on
601
+ // every API level.
661
602
  //
662
- // This is an EXPLICIT entry on every API level. On API 31+
663
- // it is legal here because the platform's auto-enter
664
- // switch is not armed: ATMS refuses a client entry only
665
- // while auto-enter is enabled ("auto-enter should take in
666
- // place instead").
603
+ // This is an EXPLICIT entry. On API 31+ it is legal here
604
+ // because the platform's auto-enter switch is not armed:
605
+ // ATMS refuses a client entry only while auto-enter is
606
+ // enabled ("auto-enter should take in place instead").
667
607
  //
668
- // On API 31+ the entry runs from
669
- // `Activity.onPictureInPictureRequested()`, while the
670
- // Activity is still RESUMED — so there is time for one
671
- // frame, and the window is asked for only once the
672
- // chrome-less frame is on the screen. Measured on
673
- // emulator-5554 (API 37) on 2026-11-05: asking for the
674
- // window in the SAME tick as the hide put the app's
675
- // PRE-HIDE frame in the PiP window, and that window carried
676
- // the app's FULL expanded chrome, scaled down.
608
+ // The ask MUST NOT be deferred. Measured on emulator-5554
609
+ // (API 37) on 2026-11-05 and again on 2026-11-06: a
610
+ // deferred ask (waiting for the window's next draw) landed
611
+ // 1.8 s after the platform's request, the Activity had been
612
+ // paused by then, and the OS REFUSED the entry — so NO PiP
613
+ // window opened at all. `enterPictureInPictureMode` needs a
614
+ // RESUMED Activity, and this callback is the last moment
615
+ // the Activity is guaranteed to be one.
677
616
  //
678
617
  // On API 24-30 the entry runs from `onUserLeaveHint()`,
679
618
  // which AOSP calls "right before the activity's onPause
680
- // callback": there is no frame between it and the pause,
681
- // and `enterPictureInPictureMode` needs a RESUMED Activity.
682
- // The entry there is immediate.
683
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
684
- if (!enterPictureInPictureAfterDraw(activity)) {
685
- Log.w(TAG, "companion.notifyUserLeaveHint: the OS refused the PiP entry")
686
- return false
687
- }
688
- Log.i(
689
- TAG,
690
- "companion.notifyUserLeaveHint: the PiP entry is scheduled for the next draw",
691
- )
692
- return true
693
- }
619
+ // callback": there is no frame between it and the pause.
620
+ // The entry there is immediate too.
694
621
  val entered = enterPictureInPicture(activity)
695
622
  if (!entered) {
696
623
  Log.w(TAG, "companion.notifyUserLeaveHint: the OS refused the PiP entry")
@@ -1003,8 +930,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
1003
930
  * chrome, scaled down.
1004
931
  *
1005
932
  * The chrome is kept out by HIDING it before the entry, in native
1006
- * code, and by having that hide DRAWN before the platform takes the
1007
- * window — see `notifyUserLeaveHint(activity)`.
933
+ * code — see `notifyUserLeaveHint(activity)`.
1008
934
  *
1009
935
  * It is **not** the picture view's box. The picture fills its lane
1010
936
  * (`StyleSheet.absoluteFill`), so the view's rect is the whole window
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "3.3.3",
3
+ "version": "3.3.4",
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",