@simba-dev/react-native-media-player 3.0.5 → 3.2.0
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 +161 -6
- package/README.md +114 -19
- package/android/src/main/java/com/simba/player/PipManager.kt +147 -33
- package/android/src/main/java/com/simba/player/PipNativeEntry.kt +86 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +478 -218
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +20 -22
- package/src/types/config.ts +32 -7
- package/src/types/player.ts +0 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
package com.simba.player
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The PURE facts of the native Picture-in-Picture entry.
|
|
5
|
+
*
|
|
6
|
+
* ## Why this file exists
|
|
7
|
+
*
|
|
8
|
+
* The HOME path enters PiP from NATIVE code — `MpvBridgeModule`'s
|
|
9
|
+
* companion, `notifyUserLeaveHint(activity)` — because by the time the
|
|
10
|
+
* user presses HOME, React Native has already paused the React
|
|
11
|
+
* scheduler with the Activity: a React commit cannot land and there is
|
|
12
|
+
* no frame clock. Measured on emulator-5554 (API 37) on 2026-11-03: the
|
|
13
|
+
* JS handler ran immediately, the effect that would have driven the
|
|
14
|
+
* entry ran 5.7 s late, and the `requestAnimationFrame` never fired.
|
|
15
|
+
*
|
|
16
|
+
* That native path has to produce the SAME two facts the JS path
|
|
17
|
+
* produces — a title and a progress percentage — and it has to format
|
|
18
|
+
* them the SAME way, because the PiP notification is one surface with
|
|
19
|
+
* two writers. A title that differs by a quote character and a
|
|
20
|
+
* percentage that differs by a space are two different facts about one
|
|
21
|
+
* playing item.
|
|
22
|
+
*
|
|
23
|
+
* So the formatting lives HERE, in plain Kotlin with no Android classes
|
|
24
|
+
* in it, and BOTH paths call it. That is what makes it testable on a
|
|
25
|
+
* plain JVM: these are the functions the unit tests exercise, and they
|
|
26
|
+
* need neither Robolectric nor a device nor a network download to run.
|
|
27
|
+
*
|
|
28
|
+
* ## What is deliberately NOT here
|
|
29
|
+
*
|
|
30
|
+
* Anything that touches Android (`View`, `Activity`,
|
|
31
|
+
* `PictureInPictureParams`) or mpv (`MPVLib`) stays in
|
|
32
|
+
* `MpvBridgeModule`. This file holds no state and has no side effects.
|
|
33
|
+
*/
|
|
34
|
+
internal object PipNativeEntry {
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The consumer's chrome `nativeID`, read from the RESOLVED config.
|
|
38
|
+
*
|
|
39
|
+
* The literal belongs to the CONSUMER: the library stores it and
|
|
40
|
+
* uses it, and never hardcodes one of its own. `null` means "this
|
|
41
|
+
* consumer has no chrome of its own", which is a real answer and
|
|
42
|
+
* not a missing value — the native path then has nothing to hide.
|
|
43
|
+
*/
|
|
44
|
+
fun chromeNativeId(config: Map<String, Any?>?): String? {
|
|
45
|
+
val pip = config?.get("pip") as? Map<*, *> ?: return null
|
|
46
|
+
val raw = pip["chromeNativeId"] as? String ?: return null
|
|
47
|
+
return raw.trim().takeIf { it.isNotEmpty() }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* mpv's `media-title` as a title, or `null` when there is none.
|
|
52
|
+
*
|
|
53
|
+
* mpv's properties come back JSON-encoded, so a string arrives
|
|
54
|
+
* wrapped in quotes (`"Overrun!"`), and a property that is not set
|
|
55
|
+
* arrives as the literal `null` — which is NOT a title.
|
|
56
|
+
*
|
|
57
|
+
* The title the consumer supplied is in here, and it is the SAME
|
|
58
|
+
* fact and not a second one: the library writes it as mpv's
|
|
59
|
+
* `force-media-title` BEFORE the load, and mpv reports it back as
|
|
60
|
+
* `media-title`.
|
|
61
|
+
*/
|
|
62
|
+
fun title(raw: String?): String? {
|
|
63
|
+
val trimmed = raw?.trim()?.trim('"')?.trim() ?: return null
|
|
64
|
+
if (trimmed.isEmpty()) return null
|
|
65
|
+
if (trimmed.equals("null", ignoreCase = true)) return null
|
|
66
|
+
return trimmed
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The progress percentage, formatted exactly as the consumer
|
|
71
|
+
* formats it: an integer, a space, then `%` — `"45 %"`.
|
|
72
|
+
*
|
|
73
|
+
* `null` when there is no duration to divide by. A percentage of an
|
|
74
|
+
* unknown length is not a fact.
|
|
75
|
+
*
|
|
76
|
+
* The rounding is JavaScript's `Math.round`, which is
|
|
77
|
+
* `floor(x + 0.5)` — not the "ties to even" rule, so the native
|
|
78
|
+
* path and the JS path cannot disagree by one percent on a .5
|
|
79
|
+
* boundary.
|
|
80
|
+
*/
|
|
81
|
+
fun progressPct(positionMs: Long, durationMs: Long): String? {
|
|
82
|
+
if (durationMs <= 0L) return null
|
|
83
|
+
val ratio = (positionMs.toDouble() / durationMs.toDouble()) * 100.0
|
|
84
|
+
return "${kotlin.math.floor(ratio + 0.5).toInt()} %"
|
|
85
|
+
}
|
|
86
|
+
}
|