@simba-dev/react-native-media-player 3.3.4 → 3.3.5
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 +45 -0
- package/README.md +17 -11
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +71 -60
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.3.5] - 2026-11-06
|
|
3
|
+
|
|
4
|
+
### Fixed
|
|
5
|
+
|
|
6
|
+
- **The HOME path was FLAKY: 2 of 5 HOME presses opened NO PiP window at all.** The 3.3.4 release
|
|
7
|
+
restored the entry — the OS ask is back inside `onPictureInPictureRequested()` — but the entry
|
|
8
|
+
path still cost up to 2.3 s, and the Activity is only RESUMED for a few hundred milliseconds
|
|
9
|
+
after the platform's request. Measured on emulator-5554 (API 37) on 2026-11-06, on the npm 3.3.4
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
16:43:59.375 onPictureInPictureRequested: the platform asked the app to enter PiP
|
|
14
|
+
16:43:59.432 hideConsumerChrome: hid the chrome view ... visibility=8
|
|
15
|
+
16:43:59.805 commitPipParams: committed the PiP params (373 ms)
|
|
16
|
+
16:44:01.003 the OS refused the PiP entry (1.2 s later)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**⇒ THE CAUSE: the entry path read the engine's state FOUR times and made TWO binder round
|
|
20
|
+
trips.** `PlaybackState.live()` reads three mpv properties over JNI — `idle-active`,
|
|
21
|
+
`eof-reached`, `pause` — and each of those blocks until mpv's core thread answers. The entry
|
|
22
|
+
path read it for the "is media loaded" guard, then again for the params builder's `playing`
|
|
23
|
+
flag, then again for its `autoEnter` policy, and then it built the params a SECOND time for
|
|
24
|
+
the entry itself.
|
|
25
|
+
|
|
26
|
+
**The fix:**
|
|
27
|
+
- the state is read **ONCE**, and that one read answers the guard, the play/pause icon and the
|
|
28
|
+
auto-enter policy;
|
|
29
|
+
- the params are built **ONCE**, and the separate `setPictureInPictureParams` round trip before
|
|
30
|
+
the entry is gone — `enterPictureInPictureMode(params)` carries them.
|
|
31
|
+
|
|
32
|
+
**⇒ twelve blocking mpv property reads become three, one params build becomes one, and two
|
|
33
|
+
binder round trips become one.** The state is still read LIVE at the moment of the entry: the
|
|
34
|
+
play/pause icon in the PiP action row is not a cached flag.
|
|
35
|
+
|
|
36
|
+
### Not claimed
|
|
37
|
+
|
|
38
|
+
- Whether the PiP window shows the app's chrome is **not** settled by this release, and this
|
|
39
|
+
release does not claim to settle it. Measured on 2026-11-06, on the npm 3.3.4 build: the PiP
|
|
40
|
+
window's **video layer is LIVE** — the frame advanced between two captures taken two minutes
|
|
41
|
+
apart — while its **UI layer is a FROZEN SNAPSHOT**, still showing the scrub row's `0:44 / 5:09`
|
|
42
|
+
from the moment of the entry. The window's draw counter did **not** move between the hide and
|
|
43
|
+
the entry (`6863 → 6863`): the hide and the entry run in the **same main-thread message**, so
|
|
44
|
+
no traversal can run between them, and the paused app never draws again. **The chrome-less
|
|
45
|
+
frame is never drawn — that is the measured cause, and it is a separate fix.**
|
|
46
|
+
|
|
2
47
|
## [3.3.4] - 2026-11-06
|
|
3
48
|
|
|
4
49
|
### Fixed
|
package/README.md
CHANGED
|
@@ -441,17 +441,23 @@ 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. **
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
444
|
+
3. **The hide is applied natively, before the entry — and the PiP window keeps a FROZEN snapshot of
|
|
445
|
+
the app's UI layer.** Measured on emulator-5554 (API 37) on 2026-11-06, on the npm 3.3.4
|
|
446
|
+
build:
|
|
447
|
+
|
|
448
|
+
- the hide lands on the **right view** — the chrome root goes `GONE` and **stays** gone (the
|
|
449
|
+
same view identity before the hide and after `onPictureInPictureModeChanged(true)`), and
|
|
450
|
+
every child of it reads `shown=false` when the platform reports the mode change;
|
|
451
|
+
- the window's draw counter does **not** move between the hide and the entry (`6863 → 6863`),
|
|
452
|
+
because the hide and the entry run in the **same main-thread message** — and a traversal can
|
|
453
|
+
only run *between* main-thread messages;
|
|
454
|
+
- the PiP window's **video layer is LIVE** (the frame advanced between two captures taken two
|
|
455
|
+
minutes apart) while its **UI layer is the app's last drawn frame** (the scrub row still read
|
|
456
|
+
`0:44 / 5:09` in both captures).
|
|
457
|
+
|
|
458
|
+
So the PiP window carries the chrome because **the chrome-less frame was never drawn**. That
|
|
459
|
+
is the measured cause. The library does **not** claim to have fixed it — the 3.3.5 CHANGELOG's
|
|
460
|
+
"Not claimed" section says so in full.
|
|
455
461
|
|
|
456
462
|
If your app's PiP window shows your chrome, the first thing to check is whether the app is
|
|
457
463
|
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
|
-
|
|
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,35 +602,49 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
590
602
|
// FULL chrome, scaled down.
|
|
591
603
|
hideConsumerChrome()
|
|
592
604
|
rememberPipActivity(activity)
|
|
593
|
-
// 5.
|
|
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
|
-
//
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
//
|
|
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:
|
|
607
618
|
//
|
|
608
|
-
//
|
|
609
|
-
//
|
|
610
|
-
//
|
|
611
|
-
//
|
|
612
|
-
//
|
|
613
|
-
//
|
|
614
|
-
//
|
|
615
|
-
//
|
|
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
|
+
// ```
|
|
624
|
+
//
|
|
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")
|
|
624
650
|
return false
|
|
@@ -700,6 +726,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
700
726
|
activity: Activity,
|
|
701
727
|
chapterTitle: String? = null,
|
|
702
728
|
progressPct: String? = null,
|
|
729
|
+
state: String = PlaybackState.live(),
|
|
703
730
|
): android.app.PictureInPictureParams {
|
|
704
731
|
// The rect of the window the VIDEO occupies. The PiP window
|
|
705
732
|
// animates FROM it — a transition hint, not a crop.
|
|
@@ -717,33 +744,19 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
717
744
|
// is read from mpv, which is the same fact.
|
|
718
745
|
chapterTitle = chapterTitle ?: nativeTitle() ?: DEFAULT_PIP_TITLE,
|
|
719
746
|
progressPercentage = progressPct ?: nativeProgressPct() ?: DEFAULT_PIP_PROGRESS,
|
|
720
|
-
|
|
747
|
+
// The SAME live read answers both questions. Reading it
|
|
748
|
+
// twice was two thirds of the entry path's mpv traffic.
|
|
749
|
+
playing = PlaybackState.isPlaying(state),
|
|
721
750
|
// The CONSUMER'S POLICY: whether the Activity may enter PiP
|
|
722
751
|
// when the user leaves the app. It is checked by the library
|
|
723
752
|
// before it enters, and it is NOT a platform switch - the
|
|
724
753
|
// platform's own auto-enter switch is never armed, because
|
|
725
754
|
// the platform would transition the window before the app
|
|
726
755
|
// could hide its chrome.
|
|
727
|
-
autoEnter =
|
|
756
|
+
autoEnter = PlaybackState.hasMedia(state),
|
|
728
757
|
)
|
|
729
758
|
}
|
|
730
759
|
|
|
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
760
|
/**
|
|
748
761
|
* The ONE owner of "how a PiP window is built".
|
|
749
762
|
*
|
|
@@ -765,6 +778,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
765
778
|
activity: Activity,
|
|
766
779
|
chapterTitle: String? = null,
|
|
767
780
|
progressPct: String? = null,
|
|
781
|
+
state: String = PlaybackState.live(),
|
|
768
782
|
): Boolean {
|
|
769
783
|
// `return try`, not a bare `try`. A `try`/`catch` in
|
|
770
784
|
// STATEMENT position is not this function's return value in
|
|
@@ -777,7 +791,23 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
777
791
|
// The ONE params builder: the same facts, the same
|
|
778
792
|
// rect, the same action — as the ones the library
|
|
779
793
|
// commits to the Activity outside the entry moment.
|
|
780
|
-
|
|
794
|
+
//
|
|
795
|
+
// The HOME path carries no title and no progress of its
|
|
796
|
+
// own, so it uses the params the library ALREADY built
|
|
797
|
+
// instead of building a second set. The build reads
|
|
798
|
+
// several mpv properties over JNI and blocks until
|
|
799
|
+
// mpv's core thread answers, and the entry path cannot
|
|
800
|
+
// afford that latency: measured on emulator-5554 (API
|
|
801
|
+
// 37) on 2026-11-06, building them twice made the
|
|
802
|
+
// entry cost 0.1-2.3 s, and the Activity is only RESUMED
|
|
803
|
+
// for a few hundred milliseconds — so 3 of 5 HOME
|
|
804
|
+
// presses were REFUSED by the OS.
|
|
805
|
+
val pipParams = buildCurrentPipParams(
|
|
806
|
+
activity,
|
|
807
|
+
chapterTitle,
|
|
808
|
+
progressPct,
|
|
809
|
+
state,
|
|
810
|
+
)
|
|
781
811
|
// `enterPictureInPictureMode` ANSWERS whether the OS
|
|
782
812
|
// accepted the request, and the answer is the only
|
|
783
813
|
// authority on this.
|
|
@@ -818,25 +848,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
818
848
|
}
|
|
819
849
|
}
|
|
820
850
|
|
|
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
851
|
/**
|
|
841
852
|
* The title for the PiP notification, read from mpv.
|
|
842
853
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.5",
|
|
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",
|