@simba-dev/react-native-media-player 1.23.0 → 2.0.1
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/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +10 -2
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +11 -1
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewRegistry.kt +132 -0
- package/android/src/main/java/com/simba/player/mpv/PlayerSurface.kt +41 -1
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewRegistryTest.kt +120 -0
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +10 -5
- package/src/bridge/NativeMpvPlayer.ts +3 -3
- package/src/bridge/__tests__/MpvPlayerModule.test.ts +53 -0
- package/src/components/PlayerProvider.tsx +18 -15
- package/src/components/PlayerRoot.tsx +23 -46
- package/src/components/PlayerSurface.tsx +27 -37
- package/src/components/__tests__/PlayerProvider.test.tsx +4 -4
- package/src/components/__tests__/PlayerRoot.test.tsx +71 -0
- package/src/index.ts +19 -5
- package/src/types/__tests__/config.test.ts +1 -1
- package/src/types/__tests__/player.test.tsx +6 -6
- package/src/types/player.ts +10 -4
- package/src/components/DefaultControls.tsx +0 -564
- package/src/components/__tests__/DefaultControls.test.tsx +0 -253
|
@@ -2171,14 +2171,22 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2171
2171
|
}
|
|
2172
2172
|
|
|
2173
2173
|
/**
|
|
2174
|
-
* Whether a video
|
|
2174
|
+
* Whether a video picture view is currently mounted.
|
|
2175
2175
|
*
|
|
2176
2176
|
* Lets a control decide its own affordance instead of assuming a surface
|
|
2177
2177
|
* exists because the user is on a video screen.
|
|
2178
|
+
*
|
|
2179
|
+
* The answer comes from [MpvRenderViewRegistry], which
|
|
2180
|
+
* [MpvRenderViewManager] writes when React Native creates a picture
|
|
2181
|
+
* view. It used to come from `PlayerSurface.current()`, whose only
|
|
2182
|
+
* writer — `PlayerSurface.mount()` — the V22 architecture never calls,
|
|
2183
|
+
* so the answer was `false` forever and `commands.openPlayer(...)`
|
|
2184
|
+
* refused **every** video, including the ones a consumer had a picture
|
|
2185
|
+
* mounted for.
|
|
2178
2186
|
*/
|
|
2179
2187
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
2180
2188
|
@Override
|
|
2181
|
-
override fun isSurfaceMounted(): Boolean =
|
|
2189
|
+
override fun isSurfaceMounted(): Boolean = MpvRenderViewRegistry.hasLiveView()
|
|
2182
2190
|
|
|
2183
2191
|
/**
|
|
2184
2192
|
* `ReadableMap` reads that tolerate absent keys.
|
|
@@ -42,7 +42,13 @@ class MpvRenderViewManager : SimpleViewManager<MpvRenderView>() {
|
|
|
42
42
|
override fun getName(): String = REACT_CLASS
|
|
43
43
|
|
|
44
44
|
override fun createViewInstance(reactContext: ThemedReactContext): MpvRenderView {
|
|
45
|
-
|
|
45
|
+
val view = MpvRenderView(reactContext)
|
|
46
|
+
// The picture is now a child of the React tree, so this manager is the
|
|
47
|
+
// only thing that knows when one exists. It publishes the view to
|
|
48
|
+
// [MpvRenderViewRegistry], which is what `isSurfaceMounted()` asks —
|
|
49
|
+
// the answer is true by construction instead of by a call nobody makes.
|
|
50
|
+
MpvRenderViewRegistry.register(view)
|
|
51
|
+
return view
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
/**
|
|
@@ -123,5 +129,9 @@ class MpvRenderViewManager : SimpleViewManager<MpvRenderView>() {
|
|
|
123
129
|
super.onDropViewInstance(view)
|
|
124
130
|
Log.i(TAG, "onDropViewInstance: releasing surface binding, engine untouched")
|
|
125
131
|
view.detachSurfaceForViewDrop()
|
|
132
|
+
// The view is going away, so there is nowhere left to put a video.
|
|
133
|
+
// `isSurfaceMounted()` must go back to answering false — otherwise a
|
|
134
|
+
// control would keep offering "play video" for a picture that is gone.
|
|
135
|
+
MpvRenderViewRegistry.unregister(view)
|
|
126
136
|
}
|
|
127
137
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
package com.simba.player.mpv
|
|
2
|
+
|
|
3
|
+
import java.lang.ref.WeakReference
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The live Fabric picture views.
|
|
7
|
+
*
|
|
8
|
+
* ## Why this file exists
|
|
9
|
+
*
|
|
10
|
+
* `PlayerSurface` was the process-wide registry of "the one surface mpv draws
|
|
11
|
+
* into". It was written by `PlayerSurface.mount()`, which the V21/V22
|
|
12
|
+
* architecture no longer calls: the picture is now a child of the React tree
|
|
13
|
+
* (`<SimbaVideo />` → `SimbaVideoView` → `MpvRenderView`), created by
|
|
14
|
+
* [MpvRenderViewManager] and destroyed by React Native.
|
|
15
|
+
*
|
|
16
|
+
* So `PlayerSurface.current()` answered `null` **forever**, and everything
|
|
17
|
+
* that asked it got a wrong answer:
|
|
18
|
+
*
|
|
19
|
+
* - `MpvBridgeModule.isSurfaceMounted()` always answered `false`, so
|
|
20
|
+
* `commands.openPlayer(...)` refused **every** video — including the ones
|
|
21
|
+
* the consumer had a picture mounted for.
|
|
22
|
+
*
|
|
23
|
+
* This registry is the replacement. It is written by the ViewManager that
|
|
24
|
+
* creates the views, so it is true by construction rather than by a call
|
|
25
|
+
* nobody makes.
|
|
26
|
+
*
|
|
27
|
+
* ## Why it is separate from `PlayerSurface`, and not a rewrite of it
|
|
28
|
+
*
|
|
29
|
+
* `PlayerSurface` also owns the mutators that place a surface
|
|
30
|
+
* (`setBounds` / `fillBounds` / `setVisible`). Those mutate `LayoutParams`
|
|
31
|
+
* from Kotlin, which `react-native-video` documents as a hazard: React
|
|
32
|
+
* Native's layout pass can be deferred for a surface view, so a surface
|
|
33
|
+
* placed outside Yoga can be measured against a stale rect. The picture is
|
|
34
|
+
* laid out by Yoga now, and it must stay that way.
|
|
35
|
+
*
|
|
36
|
+
* So this registry answers **one** question — "is there a live picture
|
|
37
|
+
* view?" — and nothing else. It cannot place a surface, and the mutators
|
|
38
|
+
* stay exactly where they were.
|
|
39
|
+
*
|
|
40
|
+
* ## Weak references, for the same reason `PlayerSurface` uses them
|
|
41
|
+
*
|
|
42
|
+
* A `View` retains its `Context`, and for a mounted surface that Context is
|
|
43
|
+
* the Activity. A strong static field would outlive `onDestroy` and pin the
|
|
44
|
+
* Activity, its window and its whole view tree for as long as the process
|
|
45
|
+
* lives — the classic static-View leak, invisible in testing and fatal in
|
|
46
|
+
* production. The registry observes the views; React Native owns them.
|
|
47
|
+
*
|
|
48
|
+
* ## Threading
|
|
49
|
+
*
|
|
50
|
+
* The ViewManager creates and drops views on the UI thread, and
|
|
51
|
+
* `isSurfaceMounted()` is read from the bridge's thread. The list is
|
|
52
|
+
* therefore guarded by its own monitor, and every read prunes the entries
|
|
53
|
+
* whose view has been collected.
|
|
54
|
+
*/
|
|
55
|
+
object MpvRenderViewRegistry {
|
|
56
|
+
|
|
57
|
+
private const val TAG = "MpvRenderViewRegistry"
|
|
58
|
+
|
|
59
|
+
/** The live picture views. Weak, so the registry never owns a View. */
|
|
60
|
+
private val refs = mutableListOf<WeakReference<MpvRenderView>>()
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Publish [view] as a live picture.
|
|
64
|
+
*
|
|
65
|
+
* Called by [MpvRenderViewManager] when it creates the view, and by
|
|
66
|
+
* nobody else — a host app does not register surfaces by hand.
|
|
67
|
+
*/
|
|
68
|
+
@JvmStatic
|
|
69
|
+
fun register(view: MpvRenderView) {
|
|
70
|
+
synchronized(refs) {
|
|
71
|
+
prune()
|
|
72
|
+
if (refs.none { it.get() === view }) {
|
|
73
|
+
refs.add(WeakReference(view))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
android.util.Log.i(TAG, "picture registered: ${System.identityHashCode(view)}")
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Withdraw [view], but only if it is still registered.
|
|
81
|
+
*
|
|
82
|
+
* Identity-safe: withdrawing a view that is not the registered one
|
|
83
|
+
* leaves the live registration alone, so a stale teardown cannot
|
|
84
|
+
* unregister its replacement.
|
|
85
|
+
*/
|
|
86
|
+
@JvmStatic
|
|
87
|
+
fun unregister(view: MpvRenderView) {
|
|
88
|
+
val removed = synchronized(refs) {
|
|
89
|
+
val before = refs.size
|
|
90
|
+
refs.removeAll { it.get() === view || it.get() == null }
|
|
91
|
+
before - refs.size
|
|
92
|
+
}
|
|
93
|
+
if (removed > 0) {
|
|
94
|
+
android.util.Log.i(TAG, "picture unregistered: ${System.identityHashCode(view)}")
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The live picture view, or `null` when none is mounted.
|
|
100
|
+
*
|
|
101
|
+
* Never cache the result — a view can be dropped at any time.
|
|
102
|
+
*/
|
|
103
|
+
@JvmStatic
|
|
104
|
+
fun current(): MpvRenderView? {
|
|
105
|
+
synchronized(refs) {
|
|
106
|
+
prune()
|
|
107
|
+
for (ref in refs) {
|
|
108
|
+
val view = ref.get()
|
|
109
|
+
if (view != null) return view
|
|
110
|
+
}
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Whether a picture view is mounted.
|
|
117
|
+
*
|
|
118
|
+
* This is the honest answer to "is there somewhere to put a video?" — a
|
|
119
|
+
* picture view exists in the React tree, so a video loaded now has
|
|
120
|
+
* somewhere to land. It does **not** claim the view is laid out or that
|
|
121
|
+
* its surface has been created: the view is created by React Native
|
|
122
|
+
* before it is attached, and mpv renders into it as soon as the
|
|
123
|
+
* `SurfaceHolder` delivers a surface.
|
|
124
|
+
*/
|
|
125
|
+
@JvmStatic
|
|
126
|
+
fun hasLiveView(): Boolean = current() != null
|
|
127
|
+
|
|
128
|
+
/** Drop the entries whose view has been collected. */
|
|
129
|
+
private fun prune() {
|
|
130
|
+
refs.removeAll { it.get() == null }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -10,7 +10,42 @@ import android.widget.FrameLayout
|
|
|
10
10
|
import java.lang.ref.WeakReference
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* The **V11 path's** process-wide registry of the single [MpvRenderView].
|
|
14
|
+
*
|
|
15
|
+
* ## Deprecated as of the V22 architecture (2026-10-29)
|
|
16
|
+
*
|
|
17
|
+
* This object was the registry of "the one surface mpv draws into". It was
|
|
18
|
+
* written by [mount], which put a `MpvRenderView` at index 0 of the host
|
|
19
|
+
* Activity's `android.R.id.content` — **beneath the React tree**, so that
|
|
20
|
+
* no screen had to blank itself around the player.
|
|
21
|
+
*
|
|
22
|
+
* The picture is no longer there. It is now a child of the React tree
|
|
23
|
+
* (`<SimbaVideo />` → `SimbaVideoView` → [MpvRenderView]), created by
|
|
24
|
+
* [MpvRenderViewManager] and destroyed by React Native. No host Activity
|
|
25
|
+
* mounts a surface any more, so **nothing calls [mount] and nothing calls
|
|
26
|
+
* [attach]** — [viewRef] is never written and [current] always answers
|
|
27
|
+
* `null`.
|
|
28
|
+
*
|
|
29
|
+
* The live answer lives in [MpvRenderViewRegistry], which the ViewManager
|
|
30
|
+
* writes. `isSurfaceMounted()` reads that registry, not this one.
|
|
31
|
+
*
|
|
32
|
+
* ## Why this object still exists
|
|
33
|
+
*
|
|
34
|
+
* The mutators below — [setBounds], [fillBounds], [setVisible] — place a
|
|
35
|
+
* surface by mutating its `LayoutParams` from Kotlin. `react-native-video`
|
|
36
|
+
* documents that as a hazard: React Native's layout pass can be deferred
|
|
37
|
+
* for a surface view, so a surface placed outside Yoga can be measured
|
|
38
|
+
* against a stale rect. The picture is laid out by Yoga now, and it must
|
|
39
|
+
* stay that way. So these mutators are kept — deprecated, not removed — but
|
|
40
|
+
* they are left with no writer, and reviving one would put the hazard back
|
|
41
|
+
* in reach.
|
|
42
|
+
*
|
|
43
|
+
* [boundsInWindow] is the PiP source-rect hint. It reads [viewRef] too, so
|
|
44
|
+
* it answers `null` and PiP entry has no rect to animate from. Fixing that
|
|
45
|
+
* is a separate piece of work: the old rect was sized by [setBounds] /
|
|
46
|
+
* [fillBounds], so it matched the video's own shape by construction, and the
|
|
47
|
+
* Yoga-sized picture does not carry that guarantee. See the app's master
|
|
48
|
+
* plan, bug `B-036`.
|
|
14
49
|
*
|
|
15
50
|
* ## Why this file exists
|
|
16
51
|
*
|
|
@@ -148,6 +183,11 @@ object PlayerSurface {
|
|
|
148
183
|
|
|
149
184
|
/**
|
|
150
185
|
* Publish the process's surface. Called by [mount].
|
|
186
|
+
*
|
|
187
|
+
* **Nothing calls this any more.** [mount] is the V11 path's only
|
|
188
|
+
* caller and the V22 architecture does not call it, so [viewRef] is
|
|
189
|
+
* never written. The live picture is published by
|
|
190
|
+
* [MpvRenderViewRegistry] instead.
|
|
151
191
|
*/
|
|
152
192
|
fun attach(view: MpvRenderView) {
|
|
153
193
|
viewRef = WeakReference(view)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
package com.simba.player.mpv
|
|
2
|
+
|
|
3
|
+
import org.junit.After
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Assert.assertSame
|
|
7
|
+
import org.junit.Assert.assertTrue
|
|
8
|
+
import org.junit.Before
|
|
9
|
+
import org.junit.Test
|
|
10
|
+
import org.mockito.kotlin.mock
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pure-JUnit unit tests for [MpvRenderViewRegistry] — the registry that
|
|
14
|
+
* answers "is there a live picture view?".
|
|
15
|
+
*
|
|
16
|
+
* These tests do NOT require the Android runtime (no Robolectric). The
|
|
17
|
+
* registry only ever stores [MpvRenderView] instances weakly and compares
|
|
18
|
+
* them by identity, so a Mockito mock stands in for a real view: the mock
|
|
19
|
+
* is never asked to behave like a View, it only has to be an object the
|
|
20
|
+
* registry can hold, compare and withdraw.
|
|
21
|
+
*
|
|
22
|
+
* ## Why this registry exists at all
|
|
23
|
+
*
|
|
24
|
+
* `PlayerSurface` was the old registry, written by `PlayerSurface.mount()`.
|
|
25
|
+
* The V22 architecture never mounts a surface — the picture is a child of
|
|
26
|
+
* the React tree — so `PlayerSurface.current()` answered `null` forever,
|
|
27
|
+
* and `isSurfaceMounted()` answered `false` forever. A consumer that had
|
|
28
|
+
* a `<SimbaVideo />` mounted was told there was nowhere to put a video.
|
|
29
|
+
*
|
|
30
|
+
* The registry is written by [MpvRenderViewManager], the thing that
|
|
31
|
+
* actually creates the views, so it is true by construction.
|
|
32
|
+
*
|
|
33
|
+
* ## Why a separate file
|
|
34
|
+
*
|
|
35
|
+
* Keeps the suite split into "always-runs" (this file, plain JUnit) and
|
|
36
|
+
* "needs-Robolectric" (the rest). CI runners without Android sandbox
|
|
37
|
+
* restrictions can run the full suite; a sandboxed environment can run
|
|
38
|
+
* just this file for the part that matters most.
|
|
39
|
+
*/
|
|
40
|
+
class MpvRenderViewRegistryTest {
|
|
41
|
+
|
|
42
|
+
/** Every mock this test registered, so @After can withdraw all of them. */
|
|
43
|
+
private val registered = mutableListOf<MpvRenderView>()
|
|
44
|
+
|
|
45
|
+
@Before
|
|
46
|
+
fun setUp() {
|
|
47
|
+
// The registry is a process-wide singleton, so a test that leaves a
|
|
48
|
+
// registration behind would make the NEXT test lie. Start clean.
|
|
49
|
+
registered.forEach { MpvRenderViewRegistry.unregister(it) }
|
|
50
|
+
registered.clear()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@After
|
|
54
|
+
fun tearDown() {
|
|
55
|
+
registered.forEach { MpvRenderViewRegistry.unregister(it) }
|
|
56
|
+
registered.clear()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private fun newPicture(): MpvRenderView {
|
|
60
|
+
val view = mock<MpvRenderView>()
|
|
61
|
+
registered.add(view)
|
|
62
|
+
return view
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Test
|
|
66
|
+
fun `with no picture registered there is no live view`() {
|
|
67
|
+
assertFalse(MpvRenderViewRegistry.hasLiveView())
|
|
68
|
+
assertNull(MpvRenderViewRegistry.current())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test
|
|
72
|
+
fun `a registered picture is the live view`() {
|
|
73
|
+
val view = newPicture()
|
|
74
|
+
MpvRenderViewRegistry.register(view)
|
|
75
|
+
|
|
76
|
+
assertTrue(MpvRenderViewRegistry.hasLiveView())
|
|
77
|
+
assertSame(view, MpvRenderViewRegistry.current())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Test
|
|
81
|
+
fun `withdrawing the picture takes the live view away`() {
|
|
82
|
+
val view = newPicture()
|
|
83
|
+
MpvRenderViewRegistry.register(view)
|
|
84
|
+
assertTrue(MpvRenderViewRegistry.hasLiveView())
|
|
85
|
+
|
|
86
|
+
MpvRenderViewRegistry.unregister(view)
|
|
87
|
+
|
|
88
|
+
assertFalse(MpvRenderViewRegistry.hasLiveView())
|
|
89
|
+
assertNull(MpvRenderViewRegistry.current())
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Test
|
|
93
|
+
fun `withdrawing a view that is not registered leaves the live one alone`() {
|
|
94
|
+
// Identity-safe: a stale teardown must not unregister its
|
|
95
|
+
// replacement. This is the same rule `PlayerSurface.detach` has.
|
|
96
|
+
val live = newPicture()
|
|
97
|
+
val stranger = newPicture()
|
|
98
|
+
MpvRenderViewRegistry.register(live)
|
|
99
|
+
|
|
100
|
+
MpvRenderViewRegistry.unregister(stranger)
|
|
101
|
+
|
|
102
|
+
assertTrue(MpvRenderViewRegistry.hasLiveView())
|
|
103
|
+
assertSame(live, MpvRenderViewRegistry.current())
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Test
|
|
107
|
+
fun `the newest registered picture does not displace the live one`() {
|
|
108
|
+
// D9: one mounted player per lane, so two picture views should
|
|
109
|
+
// not coexist. If they ever do, the registry still answers with a
|
|
110
|
+
// real view rather than with nothing.
|
|
111
|
+
val first = newPicture()
|
|
112
|
+
val second = newPicture()
|
|
113
|
+
MpvRenderViewRegistry.register(first)
|
|
114
|
+
MpvRenderViewRegistry.register(second)
|
|
115
|
+
|
|
116
|
+
assertTrue(MpvRenderViewRegistry.hasLiveView())
|
|
117
|
+
val current = MpvRenderViewRegistry.current()
|
|
118
|
+
assertTrue(current === first || current === second)
|
|
119
|
+
}
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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",
|
|
@@ -492,7 +492,13 @@ export interface MpvPlayerModuleBridge {
|
|
|
492
492
|
fillVideoBounds(): Promise<boolean>;
|
|
493
493
|
/** Show or hide the video surface. Hidden is correct for audio-only playback. */
|
|
494
494
|
setSurfaceVisible(visible: boolean): Promise<boolean>;
|
|
495
|
-
/**
|
|
495
|
+
/**
|
|
496
|
+
* Whether a video picture view is mounted in the React tree right now.
|
|
497
|
+
*
|
|
498
|
+
* The picture is a Fabric view (`SimbaVideoView`) that React Native's
|
|
499
|
+
* ViewManager creates, so this answers "is there somewhere to put a
|
|
500
|
+
* video?" — and it is false until a consumer mounts `<SimbaVideo />`.
|
|
501
|
+
*/
|
|
496
502
|
isSurfaceMounted(): boolean;
|
|
497
503
|
|
|
498
504
|
// ── Configuration (V12 Phase 21) ───────────────────────────────────────
|
|
@@ -821,7 +827,7 @@ let _emitter: NativeEventEmitter | null = null;
|
|
|
821
827
|
* V13 Phase 50: the bridge-presence check now also requires
|
|
822
828
|
* `loadFile` (the cheapest method that doesn't depend on
|
|
823
829
|
* `initPlayer()` having been called) — older V12 stubs only had
|
|
824
|
-
* the 9 methods
|
|
830
|
+
* the 9 methods the control bundle needed.
|
|
825
831
|
*/
|
|
826
832
|
function resolveBridge(): MpvPlayerModuleBridge | null {
|
|
827
833
|
const mod = (NativeModules as Record<string, unknown>).MpvPlayerModule;
|
|
@@ -901,9 +907,8 @@ export { dlog };
|
|
|
901
907
|
/**
|
|
902
908
|
* V13 Phase 50: live bridge (or no-op fallback). Consumers should
|
|
903
909
|
* always import this getter rather than reach into `NativeModules`
|
|
904
|
-
* directly — the no-op fallback is what keeps
|
|
905
|
-
*
|
|
906
|
-
* previews.
|
|
910
|
+
* directly — the no-op fallback is what keeps consumer code
|
|
911
|
+
* renderable in jest tests + Storybook + web previews.
|
|
907
912
|
*/
|
|
908
913
|
export function getMpvPlayerModule(): MpvPlayerModuleBridge {
|
|
909
914
|
const live = resolveBridge();
|
|
@@ -288,11 +288,11 @@ export interface Spec extends TurboModule {
|
|
|
288
288
|
setSurfaceVisible(visible: boolean): Promise<boolean>;
|
|
289
289
|
|
|
290
290
|
/**
|
|
291
|
-
* Whether a video
|
|
291
|
+
* Whether a video picture view is mounted in the React tree right now.
|
|
292
292
|
*
|
|
293
293
|
* Lets a control decide its own affordance instead of assuming a surface
|
|
294
|
-
* exists because the user happens to be on a video screen. Synchronous:
|
|
295
|
-
* reads a
|
|
294
|
+
* exists because the user happens to be on a video screen. Synchronous:
|
|
295
|
+
* it reads a registry of weak references.
|
|
296
296
|
*/
|
|
297
297
|
isSurfaceMounted(): boolean;
|
|
298
298
|
// ── Configuration (V12 Phase 21) ───────────────────────────────────────
|
|
@@ -107,4 +107,57 @@ describe('getMpvPlayerModule', () => {
|
|
|
107
107
|
123.456,
|
|
108
108
|
);
|
|
109
109
|
});
|
|
110
|
+
|
|
111
|
+
// ── The mock must not invent a surface ──────────────────────────────────
|
|
112
|
+
//
|
|
113
|
+
// This mock stands in for the NATIVE module. In jest there is never a
|
|
114
|
+
// picture view — a picture view is a native View that only React
|
|
115
|
+
// Native's ViewManager can create — so the honest answer to "is a surface
|
|
116
|
+
// mounted?" is `false`, and every surface mutator must refuse.
|
|
117
|
+
//
|
|
118
|
+
// The mock used to answer `true` for all four. The native implementation
|
|
119
|
+
// could only ever answer `false`, so the suite was green exactly where
|
|
120
|
+
// the product was broken, and the defect it hid was real: a deep-linked
|
|
121
|
+
// video never played, because `commands.openPlayer(...)` refused it.
|
|
122
|
+
//
|
|
123
|
+
// A mock that returns the happy answer for a method that can only fail
|
|
124
|
+
// does not test the method — it erases the defect.
|
|
125
|
+
describe('the installed native mock does not invent a surface', () => {
|
|
126
|
+
it('answers false to isSurfaceMounted', () => {
|
|
127
|
+
const bridge = getMpvPlayerModule() as MpvPlayerModuleBridge;
|
|
128
|
+
expect(bridge.isSurfaceMounted()).toBe(false);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('has every surface mutator refuse', async () => {
|
|
132
|
+
const bridge = getMpvPlayerModule() as MpvPlayerModuleBridge;
|
|
133
|
+
await expect(bridge.setVideoBounds(0, 0, 10, 10)).resolves.toBe(false);
|
|
134
|
+
await expect(bridge.fillVideoBounds()).resolves.toBe(false);
|
|
135
|
+
await expect(bridge.setSurfaceVisible(true)).resolves.toBe(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('agrees with the module own NOOP fallback on every surface call', async () => {
|
|
139
|
+
// The NOOP fallback is the module's own answer for "there is no
|
|
140
|
+
// native module at all" — and it is the same environment jest
|
|
141
|
+
// simulates. The installed mock must not disagree with it: a mock
|
|
142
|
+
// that says `true` where the fallback says `false` is the same
|
|
143
|
+
// defect wearing a different hat.
|
|
144
|
+
//
|
|
145
|
+
// The fallback is reached by removing the native module, exactly as
|
|
146
|
+
// `player.test.tsx` does; it is put back afterwards so the shared
|
|
147
|
+
// global mock is intact for the next test.
|
|
148
|
+
const native = NativeModules.MpvPlayerModule;
|
|
149
|
+
(NativeModules as {MpvPlayerModule?: unknown}).MpvPlayerModule =
|
|
150
|
+
undefined;
|
|
151
|
+
try {
|
|
152
|
+
const noop = getMpvPlayerModule();
|
|
153
|
+
expect(noop.isSurfaceMounted()).toBe(false);
|
|
154
|
+
await expect(noop.setVideoBounds(0, 0, 10, 10)).resolves.toBe(false);
|
|
155
|
+
await expect(noop.fillVideoBounds()).resolves.toBe(false);
|
|
156
|
+
await expect(noop.setSurfaceVisible(true)).resolves.toBe(false);
|
|
157
|
+
} finally {
|
|
158
|
+
(NativeModules as {MpvPlayerModule?: unknown}).MpvPlayerModule =
|
|
159
|
+
native;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
110
163
|
});
|
|
@@ -47,7 +47,7 @@ const PlayerConfigContext = createContext<ResolvedPlayerConfig | null>(null);
|
|
|
47
47
|
* Function signature for the `renderControls` slot. Takes no args —
|
|
48
48
|
* the consumer's controls component reads what it needs from
|
|
49
49
|
* `usePlayer()` (state + commands) and `useTheme()` (colors) itself.
|
|
50
|
-
* Returns the React tree to render
|
|
50
|
+
* Returns the React tree to render as the player's chrome.
|
|
51
51
|
*
|
|
52
52
|
* Why a function (not a component): the parent decides WHEN to call
|
|
53
53
|
* it (typically inside a `PlayerRoot` component), which lets us
|
|
@@ -60,7 +60,7 @@ export type RenderControlsFn = () => React.ReactNode;
|
|
|
60
60
|
* Context carrying the `renderControls` slot. Separate from the
|
|
61
61
|
* config context so consumers that only read the config don't
|
|
62
62
|
* re-render when the controls prop changes, and vice versa. `null`
|
|
63
|
-
* means "no
|
|
63
|
+
* means "no controls" — the library draws none of its own.
|
|
64
64
|
*/
|
|
65
65
|
const PlayerRenderControlsContext = createContext<RenderControlsFn | null>(null);
|
|
66
66
|
|
|
@@ -107,20 +107,22 @@ export function useTheme(): PlayerTheme {
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Phase 23 hook: read the `renderControls` slot from the nearest
|
|
110
|
-
* `<PlayerProvider>`. Returns `null` when no
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* `<PlayerProvider>`. Returns `null` when no controls were passed.
|
|
111
|
+
*
|
|
112
|
+
* **v2.0.0:** `null` means "no chrome", not "fall back to the
|
|
113
|
+
* library's controls" — the library no longer ships any. A consumer
|
|
114
|
+
* that wants controls renders them and passes them here.
|
|
113
115
|
*
|
|
114
116
|
* Returns `null` (not throws) when used outside a provider, because
|
|
115
|
-
* `<PlayerRoot>` needs to
|
|
116
|
-
*
|
|
117
|
-
*
|
|
117
|
+
* `<PlayerRoot>` needs to render without chrome in that case. The
|
|
118
|
+
* other hooks (`usePlayerConfig` / `useTheme`) throw because they
|
|
119
|
+
* have no useful fallback value.
|
|
118
120
|
*
|
|
119
121
|
* @example
|
|
120
122
|
* ```tsx
|
|
121
|
-
* function
|
|
123
|
+
* function MyPlayer() {
|
|
122
124
|
* const renderControls = useRenderControls();
|
|
123
|
-
* return renderControls != null ? renderControls() :
|
|
125
|
+
* return renderControls != null ? renderControls() : null;
|
|
124
126
|
* }
|
|
125
127
|
* ```
|
|
126
128
|
*/
|
|
@@ -436,7 +438,7 @@ export interface PlayerProviderProps {
|
|
|
436
438
|
config?: PlayerConfig;
|
|
437
439
|
/**
|
|
438
440
|
* Phase 23 slot: optional function that returns the React tree to
|
|
439
|
-
* render
|
|
441
|
+
* render as the player's chrome. The function takes no
|
|
440
442
|
* arguments — consumers that need theme / state / commands read
|
|
441
443
|
* them from `useTheme()` / `usePlayer()` inside their custom
|
|
442
444
|
* component.
|
|
@@ -450,10 +452,11 @@ export interface PlayerProviderProps {
|
|
|
450
452
|
* </PlayerProvider>
|
|
451
453
|
* ```
|
|
452
454
|
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
455
|
+
* **v2.0.0 — optional, and omitted means "no chrome".** The library
|
|
456
|
+
* draws no controls of its own, so a consumer that omits this slot
|
|
457
|
+
* gets a picture and nothing else. It stays optional on purpose:
|
|
458
|
+
* the common case is a consumer that drives the player itself and
|
|
459
|
+
* never renders a full-screen control bar at all.
|
|
457
460
|
*/
|
|
458
461
|
renderControls?: RenderControlsFn;
|
|
459
462
|
/**
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import { DefaultControls, type DefaultControlsProps } from './DefaultControls';
|
|
4
3
|
import { useRenderControls } from './PlayerProvider';
|
|
5
|
-
import { usePlayer } from '../types/player';
|
|
6
4
|
import { useLaunchPlayback } from '../hooks/useLaunchPlayback';
|
|
7
|
-
import {
|
|
8
|
-
getMpvPlayerModule,
|
|
9
|
-
type LaunchParams,
|
|
10
|
-
} from '../bridge/MpvPlayerModule';
|
|
5
|
+
import type { LaunchParams } from '../bridge/MpvPlayerModule';
|
|
11
6
|
import { PlayerSurface } from './PlayerSurface';
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
9
|
+
* The player's root: the surface, and the consumer's controls over it.
|
|
10
|
+
*
|
|
11
|
+
* ## v2.0.0 — the library draws no chrome
|
|
12
|
+
*
|
|
13
|
+
* Before 2.0.0 this component fell back to `<DefaultControls>` — the
|
|
14
|
+
* 564-line control bundle the library used to ship — whenever the
|
|
15
|
+
* consumer did not pass `renderControls`. That fallback is **gone**.
|
|
16
|
+
* The library renders **no chrome of its own**: the consumer's
|
|
17
|
+
* `renderControls` output, or nothing at all.
|
|
18
|
+
*
|
|
19
|
+
* The overlay is mounted only when there is something to put in it, so
|
|
20
|
+
* a consumer that drives the player itself (the usual case — render
|
|
21
|
+
* `<SimbaVideo />` in your own tree) gets no phantom container over
|
|
22
|
+
* the surface.
|
|
16
23
|
*
|
|
17
24
|
* V21 F5: `launchParams` is now an explicit prop with no implicit
|
|
18
25
|
* fallback. It used to fall back to `useLaunchParams()`, which read a
|
|
@@ -26,9 +33,9 @@ import { PlayerSurface } from './PlayerSurface';
|
|
|
26
33
|
* for the native SurfaceView that mpv draws into. Fills the
|
|
27
34
|
* available space via `flex: 1`.
|
|
28
35
|
* 2. **Controls overlay** (Phase 23 + 24): the consumer's custom
|
|
29
|
-
* controls
|
|
30
|
-
*
|
|
31
|
-
*
|
|
36
|
+
* controls, via `renderControls`. Absolutely positioned over the
|
|
37
|
+
* surface so the video fills the screen and the controls layer on
|
|
38
|
+
* top.
|
|
32
39
|
*
|
|
33
40
|
* Wiring example for a consumer:
|
|
34
41
|
*
|
|
@@ -52,9 +59,6 @@ import { PlayerSurface } from './PlayerSurface';
|
|
|
52
59
|
* insets (`top / left / right / bottom: 0`) so it stretches over
|
|
53
60
|
* the surface without affecting its layout. The surface owns the
|
|
54
61
|
* flex layout for the tree; the controls float on top.
|
|
55
|
-
* - The fallback path reads `usePlayer()` and passes
|
|
56
|
-
* `state.title / state.artist` + `commands.play / pause` through
|
|
57
|
-
* to `<DefaultControls>`.
|
|
58
62
|
* - When `renderControls` is provided, we render its output
|
|
59
63
|
* wrapped in the same absolutely-positioned overlay container,
|
|
60
64
|
* so custom controls don't need to handle their own
|
|
@@ -84,7 +88,6 @@ export function PlayerRoot({
|
|
|
84
88
|
launchParams,
|
|
85
89
|
}: PlayerRootProps = {}): React.ReactElement {
|
|
86
90
|
const renderControls = useRenderControls();
|
|
87
|
-
const { state, commands } = usePlayer();
|
|
88
91
|
|
|
89
92
|
// V22.0.0 / 1.5.8 (D-035 fix #3 + #5 + #7): feed the launch URI to
|
|
90
93
|
// mpv exactly once per `(uri, startPositionMs)` payload, NOT once
|
|
@@ -94,41 +97,15 @@ export function PlayerRoot({
|
|
|
94
97
|
// the URI actually changes.
|
|
95
98
|
useLaunchPlayback(launchParams);
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const props: DefaultControlsProps = {
|
|
102
|
-
title: state.title || 'Simba Player',
|
|
103
|
-
subtitle:
|
|
104
|
-
state.artist && state.album
|
|
105
|
-
? `${state.artist} • ${state.album}`
|
|
106
|
-
: state.artist || state.album || undefined,
|
|
107
|
-
onPlay: commands.play,
|
|
108
|
-
onPause: commands.pause,
|
|
109
|
-
// V22.0.0 / 1.5.8 (D-035 fix #4): the close ✕ button calls
|
|
110
|
-
// `exitPipAndFinish` on the bridge, which dismisses the
|
|
111
|
-
// activity + tears down the SurfaceView properly. Falls back
|
|
112
|
-
// to the no-op `close` command when the bridge is absent
|
|
113
|
-
// (jest / web preview).
|
|
114
|
-
onClose:
|
|
115
|
-
typeof (getMpvPlayerModule().exitPipAndFinish) === 'function'
|
|
116
|
-
? () => {
|
|
117
|
-
try {
|
|
118
|
-
getMpvPlayerModule().exitPipAndFinish();
|
|
119
|
-
} catch {
|
|
120
|
-
// ignore
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
: undefined,
|
|
124
|
-
};
|
|
125
|
-
return <DefaultControls {...props} />;
|
|
126
|
-
})();
|
|
100
|
+
// The library draws no chrome. Whatever the consumer supplied is
|
|
101
|
+
// what appears over the surface; if the consumer supplied nothing,
|
|
102
|
+
// there is nothing to draw.
|
|
103
|
+
const controls = renderControls != null ? renderControls() : null;
|
|
127
104
|
|
|
128
105
|
return (
|
|
129
106
|
<View style={styles.root}>
|
|
130
107
|
<PlayerSurface />
|
|
131
|
-
<View style={styles.overlay}>{
|
|
108
|
+
{controls != null ? <View style={styles.overlay}>{controls}</View> : null}
|
|
132
109
|
</View>
|
|
133
110
|
);
|
|
134
111
|
}
|