@simba-dev/react-native-media-player 3.3.4 → 3.3.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,94 @@
1
1
 
2
+ ## [3.3.6] - 2026-11-06
3
+
4
+ ### Fixed
5
+
6
+ - **A REFUSED Picture-in-Picture entry left the app with NO controls at all.** The entry path hides
7
+ your chrome before it asks the OS for the window. If the OS then **refused** the entry, the
8
+ chrome was never brought back: `restoreConsumerChrome()` was called from exactly one place —
9
+ `onPictureInPictureModeChanged(false)` — and a refused entry never produces a Picture-in-Picture
10
+ mode change, because the app never entered Picture-in-Picture.
11
+
12
+ Measured on emulator-5554 (API 37) on 2026-11-06, on the npm 3.3.5 build, with the platform
13
+ appop `PICTURE_IN_PICTURE` denied so the OS refuses the entry:
14
+
15
+ ```
16
+ 18:14:49.334 hideConsumerChrome: hid the chrome view with nativeID 'simba-expanded-chrome' visibility=8
17
+ 18:14:49.348 the OS refused the PiP entry
18
+ ```
19
+
20
+ `restoreConsumerChrome` **never ran**. The app came back to the player with no header, no scrub
21
+ row and no transport row — just the video, with nothing to control it with. Tapping the video did
22
+ not bring it back, and the only recovery was killing the app.
23
+
24
+ **The fix:** the refusal branch brings the chrome back itself, before it returns. It calls the
25
+ **one** owner — `restoreConsumerChrome()` — which forgets the hidden view as it restores it, so
26
+ the refusal path and the Picture-in-Picture-exit path can both call it and the chrome is restored
27
+ **exactly once**: whichever path gets there first restores it, and the other finds nothing to do
28
+ and does nothing. A guard that returns *before* the hide (the API level, the auto-enter policy,
29
+ already-in-Picture-in-Picture, no media loaded) restores nothing, because nothing was hidden.
30
+
31
+ The README said the chrome is brought back "when Picture-in-Picture ends". That was **false** for
32
+ a refused entry, and the README is the documentation every consumer installs — so it now says
33
+ "when Picture-in-Picture ends **or when the OS refuses the entry**".
34
+
35
+ ### Not claimed
36
+
37
+ - This release does **not** claim to fix the chrome that is still in the Picture-in-Picture window
38
+ on a successful entry. That is **B-050**, and its cause is measured: the hide and the entry run
39
+ in the **same main-thread message**, so no traversal can run between them, so the chrome-less
40
+ frame is never drawn, and the Picture-in-Picture window keeps a **frozen snapshot** of the app's
41
+ last drawn UI layer while its video layer stays live. The 3.3.5 CHANGELOG's "Not claimed" section
42
+ says so in full, and nothing in this release changes it.
43
+
44
+ - The JavaScript-button entry path is unchanged: the consumer unmounts its own chrome in React
45
+ there, so the library never hides it natively and there is nothing to restore.
46
+
47
+ ## [3.3.5] - 2026-11-06
48
+
49
+ ### Fixed
50
+
51
+ - **The HOME path was FLAKY: 2 of 5 HOME presses opened NO PiP window at all.** The 3.3.4 release
52
+ restored the entry — the OS ask is back inside `onPictureInPictureRequested()` — but the entry
53
+ path still cost up to 2.3 s, and the Activity is only RESUMED for a few hundred milliseconds
54
+ after the platform's request. Measured on emulator-5554 (API 37) on 2026-11-06, on the npm 3.3.4
55
+ build:
56
+
57
+ ```
58
+ 16:43:59.375 onPictureInPictureRequested: the platform asked the app to enter PiP
59
+ 16:43:59.432 hideConsumerChrome: hid the chrome view ... visibility=8
60
+ 16:43:59.805 commitPipParams: committed the PiP params (373 ms)
61
+ 16:44:01.003 the OS refused the PiP entry (1.2 s later)
62
+ ```
63
+
64
+ **⇒ THE CAUSE: the entry path read the engine's state FOUR times and made TWO binder round
65
+ trips.** `PlaybackState.live()` reads three mpv properties over JNI — `idle-active`,
66
+ `eof-reached`, `pause` — and each of those blocks until mpv's core thread answers. The entry
67
+ path read it for the "is media loaded" guard, then again for the params builder's `playing`
68
+ flag, then again for its `autoEnter` policy, and then it built the params a SECOND time for
69
+ the entry itself.
70
+
71
+ **The fix:**
72
+ - the state is read **ONCE**, and that one read answers the guard, the play/pause icon and the
73
+ auto-enter policy;
74
+ - the params are built **ONCE**, and the separate `setPictureInPictureParams` round trip before
75
+ the entry is gone — `enterPictureInPictureMode(params)` carries them.
76
+
77
+ **⇒ twelve blocking mpv property reads become three, one params build becomes one, and two
78
+ binder round trips become one.** The state is still read LIVE at the moment of the entry: the
79
+ play/pause icon in the PiP action row is not a cached flag.
80
+
81
+ ### Not claimed
82
+
83
+ - Whether the PiP window shows the app's chrome is **not** settled by this release, and this
84
+ release does not claim to settle it. Measured on 2026-11-06, on the npm 3.3.4 build: the PiP
85
+ window's **video layer is LIVE** — the frame advanced between two captures taken two minutes
86
+ apart — while its **UI layer is a FROZEN SNAPSHOT**, still showing the scrub row's `0:44 / 5:09`
87
+ from the moment of the entry. The window's draw counter did **not** move between the hide and
88
+ the entry (`6863 → 6863`): the hide and the entry run in the **same main-thread message**, so
89
+ no traversal can run between them, and the paused app never draws again. **The chrome-less
90
+ frame is never drawn — that is the measured cause, and it is a separate fix.**
91
+
2
92
  ## [3.3.4] - 2026-11-06
3
93
 
4
94
  ### Fixed
package/README.md CHANGED
@@ -387,8 +387,9 @@ 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 OS **accepted** the entry, and `false` when the
391
- entry was refused, so you can log it:
390
+ Picture-in-Picture ends **— or when the OS refuses the entry**, which produces no Picture-in-Picture
391
+ mode change to restore it from. It returns whether the OS **accepted** the entry, and `false` when
392
+ the entry was refused, so you can log it:
392
393
 
393
394
  ```kotlin
394
395
  val entered = com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint(this)
@@ -441,17 +442,23 @@ Three things have to be right for that to work:
441
442
  2. **The entry happens while your Activity is resumed.** On API 31+ that means
442
443
  `onPictureInPictureRequested()`; see
443
444
  [Why it is native](#why-it-is-native-and-why-your-activity-hands-over-the-activity).
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.
445
+ 3. **The hide is applied natively, before the entry — and the PiP window keeps a FROZEN snapshot of
446
+ the app's UI layer.** Measured on emulator-5554 (API 37) on 2026-11-06, on the npm 3.3.4
447
+ build:
448
+
449
+ - the hide lands on the **right view** — the chrome root goes `GONE` and **stays** gone (the
450
+ same view identity before the hide and after `onPictureInPictureModeChanged(true)`), and
451
+ every child of it reads `shown=false` when the platform reports the mode change;
452
+ - the window's draw counter does **not** move between the hide and the entry (`6863 → 6863`),
453
+ because the hide and the entry run in the **same main-thread message** — and a traversal can
454
+ only run *between* main-thread messages;
455
+ - the PiP window's **video layer is LIVE** (the frame advanced between two captures taken two
456
+ minutes apart) while its **UI layer is the app's last drawn frame** (the scrub row still read
457
+ `0:44 / 5:09` in both captures).
458
+
459
+ So the PiP window carries the chrome because **the chrome-less frame was never drawn**. That
460
+ is the measured cause. The library does **not** claim to have fixed it — the 3.3.5 CHANGELOG's
461
+ "Not claimed" section says so in full.
455
462
 
456
463
  If your app's PiP window shows your chrome, the first thing to check is whether the app is
457
464
  still drawing at the moment of the entry.
@@ -564,7 +564,19 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
564
564
  }
565
565
  // 3. No media loaded: a PiP window for a stopped session is
566
566
  // a bug, not a feature.
567
- if (!isMediaLoaded()) {
567
+ //
568
+ // The state is read ONCE, here, and the SAME read answers
569
+ // this guard and the params below. It used to be read
570
+ // twice — once for the guard and once again inside the
571
+ // params builder — and `PlaybackState.live()` reads three
572
+ // mpv properties over JNI, each of which blocks until mpv's
573
+ // core thread answers. Measured on emulator-5554 (API 37) on
574
+ // 2026-11-06: the entry path made TWELVE such reads, and
575
+ // the entry succeeded only when the whole path happened to
576
+ // fit inside the few hundred milliseconds the Activity stays
577
+ // RESUMED.
578
+ val state = PlaybackState.live()
579
+ if (!PlaybackState.hasMedia(state)) {
568
580
  Log.i(TAG, "companion.notifyUserLeaveHint: no media loaded; not entering PiP")
569
581
  return false
570
582
  }
@@ -590,37 +602,69 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
590
602
  // FULL chrome, scaled down.
591
603
  hideConsumerChrome()
592
604
  rememberPipActivity(activity)
593
- // 5. Commit the params BEFORE the window is asked for.
594
- //
595
- // The platform builds the PiP window from the LAST
596
- // COMMITTED params. The source rect hint among them is the
597
- // region the PiP window ANIMATES FROM — a transition hint,
598
- // not a crop.
599
- commitPipParams(activity)
600
- // 6. Ask for the window — SYNCHRONOUSLY, in this callback, on
605
+ // 5. Ask for the window — SYNCHRONOUSLY, in this callback, on
601
606
  // every API level.
602
607
  //
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").
608
+ // The entry path READS the state ONCE and COMMITS NOTHING:
609
+ // `enterPictureInPictureMode(params)` carries the params, so
610
+ // the separate `setPictureInPictureParams` round trip before
611
+ // it is gone.
612
+ //
613
+ // That is a measured fix, not a tidy-up. Measured on
614
+ // emulator-5554 (API 37) on 2026-11-06, the HOME entry was
615
+ // FLAKY: 2 of 5 HOME presses opened a PiP window and the
616
+ // other 3 were REFUSED by the OS. The log splits the entry
617
+ // path's latency:
618
+ //
619
+ // ```
620
+ // 16:43:59.432 hideConsumerChrome
621
+ // 16:43:59.805 commitPipParams: committed the PiP params (373 ms)
622
+ // 16:44:01.003 the OS refused the PiP entry (1.2 s later)
623
+ // ```
607
624
  //
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.
625
+ // The path built the params TWICE — each build reads several
626
+ // mpv properties over JNI, and `mpv_get_property` blocks
627
+ // until mpv's core thread answers — and made two binder
628
+ // round trips. It cost 0.1-2.3 s. The Activity is only
629
+ // RESUMED for a few hundred milliseconds after the
630
+ // platform's request, so the entry succeeded only when the
631
+ // path happened to be fast.
632
+ //
633
+ // The ask MUST NOT be deferred either. Measured on
634
+ // emulator-5554 (API 37) on 2026-11-05 and again on
635
+ // 2026-11-06: a deferred ask (waiting for the window's next
636
+ // draw) landed 1.8 s after the platform's request, the
637
+ // Activity had been paused by then, and the OS REFUSED the
638
+ // entry — so NO PiP window opened at all.
639
+ // `enterPictureInPictureMode` needs a RESUMED Activity, and
640
+ // this callback is the last moment the Activity is
641
+ // guaranteed to be one.
616
642
  //
617
643
  // On API 24-30 the entry runs from `onUserLeaveHint()`,
618
644
  // which AOSP calls "right before the activity's onPause
619
645
  // callback": there is no frame between it and the pause.
620
646
  // The entry there is immediate too.
621
- val entered = enterPictureInPicture(activity)
647
+ val entered = enterPictureInPicture(activity, state = state)
622
648
  if (!entered) {
623
649
  Log.w(TAG, "companion.notifyUserLeaveHint: the OS refused the PiP entry")
650
+ // The chrome was hidden above, and a REFUSED entry never
651
+ // produces a PiP mode change: the app never entered PiP, so
652
+ // `onPictureInPictureModeChanged(false)` never runs and the
653
+ // restore it owns never happens.
654
+ //
655
+ // The consumer came back to the player with NO header, no
656
+ // scrub row and no transport row at all, and the only
657
+ // recovery was killing the app. Measured on emulator-5554
658
+ // (API 37) on 2026-11-06: the OS refused the entry and
659
+ // `restoreConsumerChrome` NEVER ran.
660
+ //
661
+ // So the refusal brings the chrome back ITSELF - and it
662
+ // calls the ONE owner, `restoreConsumerChrome()`, which
663
+ // forgets the hidden view as it restores it. That is what
664
+ // makes this call and the PiP-exit call safe to have
665
+ // BOTH: the second one finds nothing to restore and does
666
+ // nothing, so the chrome is restored exactly once.
667
+ restoreConsumerChrome()
624
668
  return false
625
669
  }
626
670
  Log.i(TAG, "companion.notifyUserLeaveHint: entered PiP")
@@ -700,6 +744,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
700
744
  activity: Activity,
701
745
  chapterTitle: String? = null,
702
746
  progressPct: String? = null,
747
+ state: String = PlaybackState.live(),
703
748
  ): android.app.PictureInPictureParams {
704
749
  // The rect of the window the VIDEO occupies. The PiP window
705
750
  // animates FROM it — a transition hint, not a crop.
@@ -717,33 +762,19 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
717
762
  // is read from mpv, which is the same fact.
718
763
  chapterTitle = chapterTitle ?: nativeTitle() ?: DEFAULT_PIP_TITLE,
719
764
  progressPercentage = progressPct ?: nativeProgressPct() ?: DEFAULT_PIP_PROGRESS,
720
- playing = isPlaying(),
765
+ // The SAME live read answers both questions. Reading it
766
+ // twice was two thirds of the entry path's mpv traffic.
767
+ playing = PlaybackState.isPlaying(state),
721
768
  // The CONSUMER'S POLICY: whether the Activity may enter PiP
722
769
  // when the user leaves the app. It is checked by the library
723
770
  // before it enters, and it is NOT a platform switch - the
724
771
  // platform's own auto-enter switch is never armed, because
725
772
  // the platform would transition the window before the app
726
773
  // could hide its chrome.
727
- autoEnter = isMediaLoaded(),
774
+ autoEnter = PlaybackState.hasMedia(state),
728
775
  )
729
776
  }
730
777
 
731
- /**
732
- * Whether the engine is playing right now.
733
- *
734
- * Read from mpv's REAL properties (`idle-active`, `eof-reached`,
735
- * `pause`) at the moment of use, and never from a JS flag: the PiP
736
- * action's icon has to be true even when the app is paused and no
737
- * JS is running.
738
- */
739
- private fun isPlaying(): Boolean {
740
- // ONE owner: `PlaybackState`, which reads mpv's REAL
741
- // properties. This used to read `playback-state`, a property
742
- // mpv does NOT have, so the answer was always "not playing"
743
- // and the PiP action's icon never changed.
744
- return PlaybackState.isPlayingNow()
745
- }
746
-
747
778
  /**
748
779
  * The ONE owner of "how a PiP window is built".
749
780
  *
@@ -765,6 +796,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
765
796
  activity: Activity,
766
797
  chapterTitle: String? = null,
767
798
  progressPct: String? = null,
799
+ state: String = PlaybackState.live(),
768
800
  ): Boolean {
769
801
  // `return try`, not a bare `try`. A `try`/`catch` in
770
802
  // STATEMENT position is not this function's return value in
@@ -777,7 +809,23 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
777
809
  // The ONE params builder: the same facts, the same
778
810
  // rect, the same action — as the ones the library
779
811
  // commits to the Activity outside the entry moment.
780
- val pipParams = buildCurrentPipParams(activity, chapterTitle, progressPct)
812
+ //
813
+ // The HOME path carries no title and no progress of its
814
+ // own, so it uses the params the library ALREADY built
815
+ // instead of building a second set. The build reads
816
+ // several mpv properties over JNI and blocks until
817
+ // mpv's core thread answers, and the entry path cannot
818
+ // afford that latency: measured on emulator-5554 (API
819
+ // 37) on 2026-11-06, building them twice made the
820
+ // entry cost 0.1-2.3 s, and the Activity is only RESUMED
821
+ // for a few hundred milliseconds — so 3 of 5 HOME
822
+ // presses were REFUSED by the OS.
823
+ val pipParams = buildCurrentPipParams(
824
+ activity,
825
+ chapterTitle,
826
+ progressPct,
827
+ state,
828
+ )
781
829
  // `enterPictureInPictureMode` ANSWERS whether the OS
782
830
  // accepted the request, and the answer is the only
783
831
  // authority on this.
@@ -805,7 +853,21 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
805
853
  /**
806
854
  * Bring the hidden chrome back, and forget it.
807
855
  *
808
- * Called when PiP ends (`onPictureInPictureModeChanged(false)`).
856
+ * ## The ONE owner of the restore
857
+ *
858
+ * Two paths call it, and both go through here:
859
+ * - PiP ends - `onPictureInPictureModeChanged(false)`;
860
+ * - the OS REFUSED the entry - `notifyUserLeaveHint`, which
861
+ * never produces a PiP mode change at all, because the app
862
+ * never entered PiP.
863
+ *
864
+ * It forgets the hidden view as it restores it, so a second call
865
+ * finds nothing to do: whichever path gets there first restores
866
+ * the chrome, and the other one does nothing. The chrome is
867
+ * restored exactly once, and never zero times.
868
+ *
869
+ * A `null` view is not a failure: nothing was hidden, so there is
870
+ * nothing to restore.
809
871
  */
810
872
  private fun restoreConsumerChrome() {
811
873
  val view = pipHiddenChromeView ?: return
@@ -818,25 +880,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
818
880
  }
819
881
  }
820
882
 
821
- /**
822
- * Whether mpv currently has media loaded.
823
- *
824
- * Read live through [PlaybackHost] — never from a JS flag, which
825
- * can be stale by the time the user presses HOME. The question is
826
- * answered by mpv's REAL properties (`idle-active`, `eof-reached`,
827
- * `pause`), and the vocabulary is the one the library has always
828
- * published: `idle` and `stopped` mean no media, and `paused` and
829
- * `playing` mean something is still loaded.
830
- */
831
- private fun isMediaLoaded(): Boolean {
832
- // ONE owner: `PlaybackState`, which reads mpv's REAL
833
- // properties. This used to read `playback-state`, a property
834
- // mpv does NOT have — the read failed, and "not idle, not
835
- // stopped" was therefore true for EVERY value, so the library
836
- // thought media was always loaded.
837
- return PlaybackState.hasMediaNow()
838
- }
839
-
840
883
  /**
841
884
  * The title for the PiP notification, read from mpv.
842
885
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "3.3.4",
3
+ "version": "3.3.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",