@simba-dev/react-native-media-player 2.1.0 → 3.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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",
|
|
@@ -50,7 +50,7 @@ const PlayerConfigContext = createContext<ResolvedPlayerConfig | null>(null);
|
|
|
50
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
|
-
* it (typically
|
|
53
|
+
* it (typically in the consumer's own tree), which lets us
|
|
54
54
|
* wrap the result in error boundaries / suspense fallbacks in a
|
|
55
55
|
* future phase without changing the consumer's API.
|
|
56
56
|
*/
|
|
@@ -114,8 +114,8 @@ export function useTheme(): PlayerTheme {
|
|
|
114
114
|
* that wants controls renders them and passes them here.
|
|
115
115
|
*
|
|
116
116
|
* Returns `null` (not throws) when used outside a provider, because
|
|
117
|
-
*
|
|
118
|
-
* other hooks (`usePlayerConfig` / `useTheme`) throw because they
|
|
117
|
+
* a consumer's own root needs to render without chrome in that case.
|
|
118
|
+
* The other hooks (`usePlayerConfig` / `useTheme`) throw because they
|
|
119
119
|
* have no useful fallback value.
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
@@ -479,8 +479,8 @@ export interface PlayerProviderProps {
|
|
|
479
479
|
* The `renderControls` slot is intentionally NOT pushed to the native
|
|
480
480
|
* side — it's a JS-only concept (a function reference can't be
|
|
481
481
|
* serialised to JSON). Consumer apps wrap their PlayerActivity's JS
|
|
482
|
-
* tree with `<PlayerProvider renderControls={...}>` and
|
|
483
|
-
*
|
|
482
|
+
* tree with `<PlayerProvider renderControls={...}>` and their own
|
|
483
|
+
* component reads it via `useRenderControls()`.
|
|
484
484
|
*
|
|
485
485
|
* V13 Phase 51: in addition to config + renderControls, the provider
|
|
486
486
|
* now holds the live player state. The state is updated by:
|
package/src/index.ts
CHANGED
|
@@ -41,9 +41,26 @@
|
|
|
41
41
|
* the surface and the consumer's controls, and **nothing else** when
|
|
42
42
|
* `renderControls` is absent.
|
|
43
43
|
*
|
|
44
|
-
* This is a **breaking** change, hence the major version.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* This is a **breaking** change, hence the major version.
|
|
45
|
+
*
|
|
46
|
+
* ## v3.0.0 — the vestigial root and surface are gone
|
|
47
|
+
*
|
|
48
|
+
* `<PlayerRoot>` and `<PlayerSurface>` are **removed**. They were the
|
|
49
|
+
* JS-side remainder of an arrangement that ended in 2.0.0: a native
|
|
50
|
+
* `SurfaceView` pinned to the Activity root, with a transparent React box
|
|
51
|
+
* standing in for it so a controls overlay had a rectangle to anchor to.
|
|
52
|
+
*
|
|
53
|
+
* The picture is `<SimbaVideo>` now — a Fabric component in the
|
|
54
|
+
* consumer's own tree, with React Native owning its layout, its z-order
|
|
55
|
+
* and its lifecycle — so there is no surface for a placeholder to
|
|
56
|
+
* reserve. Neither component had an importer: in this package and in its
|
|
57
|
+
* host app, the only reference to either was its own export.
|
|
58
|
+
*
|
|
59
|
+
* A consumer that used `<PlayerRoot>` for its **launch** — the one job it
|
|
60
|
+
* still had — loses nothing: `useLaunchPlayback` is still exported, and
|
|
61
|
+
* it is still the once-per-payload load. A consumer that used it for the
|
|
62
|
+
* **overlay** composes the same thing from a `View` and its own
|
|
63
|
+
* `renderControls`.
|
|
47
64
|
*/
|
|
48
65
|
|
|
49
66
|
export {
|
|
@@ -55,16 +72,12 @@ export {
|
|
|
55
72
|
type RenderControlsFn,
|
|
56
73
|
} from './components/PlayerProvider';
|
|
57
74
|
|
|
58
|
-
export { PlayerRoot } from './components/PlayerRoot';
|
|
59
|
-
|
|
60
75
|
export {
|
|
61
76
|
SimbaVideo,
|
|
62
77
|
type SimbaVideoProps,
|
|
63
78
|
type SimbaVideoResizeMode,
|
|
64
79
|
} from './components/SimbaVideo';
|
|
65
80
|
|
|
66
|
-
export { PlayerSurface, type PlayerSurfaceProps } from './components/PlayerSurface';
|
|
67
|
-
|
|
68
81
|
export {
|
|
69
82
|
type AudioConfig,
|
|
70
83
|
type DebugConfig,
|
|
@@ -142,11 +155,11 @@ export {
|
|
|
142
155
|
DEFAULT_FRAME_QUALITY,
|
|
143
156
|
type CaptureFrameOptions,
|
|
144
157
|
} from './hooks/useResumeThumbnail';
|
|
145
|
-
// V21 F5 — the
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
// once
|
|
158
|
+
// V21 F5 — the in-window launch primitive. Video no longer starts an
|
|
159
|
+
// Activity, so a consumer that wants to play media into its own
|
|
160
|
+
// already-mounted surface drives it from here: pass the payload, and
|
|
161
|
+
// `useLaunchPlayback` loads it exactly once. See its docstring for the
|
|
162
|
+
// once-per-payload contract.
|
|
150
163
|
export {useLaunchPlayback} from './hooks/useLaunchPlayback';
|
|
151
164
|
|
|
152
165
|
export {
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import { useRenderControls } from './PlayerProvider';
|
|
4
|
-
import { useLaunchPlayback } from '../hooks/useLaunchPlayback';
|
|
5
|
-
import type { LaunchParams } from '../bridge/MpvPlayerModule';
|
|
6
|
-
import { PlayerSurface } from './PlayerSurface';
|
|
7
|
-
|
|
8
|
-
/**
|
|
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.
|
|
23
|
-
*
|
|
24
|
-
* V21 F5: `launchParams` is now an explicit prop with no implicit
|
|
25
|
-
* fallback. It used to fall back to `useLaunchParams()`, which read a
|
|
26
|
-
* one-shot native queue that only a second Activity ever filled — so the
|
|
27
|
-
* fallback could not fire, and keeping it would have been a branch that
|
|
28
|
-
* looked live and was not. Pass the payload in, or drive loading
|
|
29
|
-
* yourself with the exported `useLaunchPlayback`.
|
|
30
|
-
*
|
|
31
|
-
* Renders the full player UI in two layers:
|
|
32
|
-
* 1. **`<PlayerSurface />`** (Phase 25): the JS-side placeholder
|
|
33
|
-
* for the native SurfaceView that mpv draws into. Fills the
|
|
34
|
-
* available space via `flex: 1`.
|
|
35
|
-
* 2. **Controls overlay** (Phase 23 + 24): the consumer's custom
|
|
36
|
-
* controls, via `renderControls`. Absolutely positioned over the
|
|
37
|
-
* surface so the video fills the screen and the controls layer on
|
|
38
|
-
* top.
|
|
39
|
-
*
|
|
40
|
-
* Wiring example for a consumer:
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* function App() {
|
|
45
|
-
* return (
|
|
46
|
-
* <PlayerProvider
|
|
47
|
-
* config={{ theme: { accent: '#FFD700' } }}
|
|
48
|
-
* renderControls={() => <MyCustomControls />}
|
|
49
|
-
* >
|
|
50
|
-
* <PlayerRoot />
|
|
51
|
-
* </PlayerProvider>
|
|
52
|
-
* );
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* Design notes
|
|
57
|
-
* ------------
|
|
58
|
-
* - The controls overlay uses `position: 'absolute'` + the four
|
|
59
|
-
* insets (`top / left / right / bottom: 0`) so it stretches over
|
|
60
|
-
* the surface without affecting its layout. The surface owns the
|
|
61
|
-
* flex layout for the tree; the controls float on top.
|
|
62
|
-
* - When `renderControls` is provided, we render its output
|
|
63
|
-
* wrapped in the same absolutely-positioned overlay container,
|
|
64
|
-
* so custom controls don't need to handle their own
|
|
65
|
-
* positioning — they Just Work over the surface.
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* V22.0.0 / 1.5.8 (D-035 fix #5): optional `launchParams` prop.
|
|
69
|
-
*
|
|
70
|
-
* `<SimbaPlayerRoot>` already calls `useLaunchParams()` once at the
|
|
71
|
-
* activity boundary. If we also called it here, the second read would
|
|
72
|
-
* hit an empty one-shot queue (the first read consumed it) and we'd
|
|
73
|
-
* fall through to the `null` branch — leaving the screen with no
|
|
74
|
-
* media loaded. Letting the parent pass `launchParams` down as a
|
|
75
|
-
* prop means the player root always sees the resolved payload.
|
|
76
|
-
*
|
|
77
|
-
* Direct consumers that mount `<PlayerRoot />` without
|
|
78
|
-
* `<SimbaPlayerRoot>` (rare; legacy V11/V12 patterns) keep working:
|
|
79
|
-
* when `launchParams` is left `undefined` we fall back to the hook,
|
|
80
|
-
* which reads the queue exactly once and returns `null` on
|
|
81
|
-
* subsequent mounts.
|
|
82
|
-
*/
|
|
83
|
-
export interface PlayerRootProps {
|
|
84
|
-
launchParams?: LaunchParams | null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function PlayerRoot({
|
|
88
|
-
launchParams,
|
|
89
|
-
}: PlayerRootProps = {}): React.ReactElement {
|
|
90
|
-
const renderControls = useRenderControls();
|
|
91
|
-
|
|
92
|
-
// V22.0.0 / 1.5.8 (D-035 fix #3 + #5 + #7): feed the launch URI to
|
|
93
|
-
// mpv exactly once per `(uri, startPositionMs)` payload, NOT once
|
|
94
|
-
// per render. `useLaunchPlayback` owns that contract.
|
|
95
|
-
// The effect is keyed on the URI + start position, so it fires once
|
|
96
|
-
// when the payload resolves to a real URI, then never again until
|
|
97
|
-
// the URI actually changes.
|
|
98
|
-
useLaunchPlayback(launchParams);
|
|
99
|
-
|
|
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;
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<View style={styles.root}>
|
|
107
|
-
<PlayerSurface />
|
|
108
|
-
{controls != null ? <View style={styles.overlay}>{controls}</View> : null}
|
|
109
|
-
</View>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const styles = StyleSheet.create({
|
|
114
|
-
root: {
|
|
115
|
-
flex: 1,
|
|
116
|
-
},
|
|
117
|
-
overlay: {
|
|
118
|
-
position: 'absolute',
|
|
119
|
-
top: 0,
|
|
120
|
-
left: 0,
|
|
121
|
-
right: 0,
|
|
122
|
-
bottom: 0,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export interface PlayerSurfaceProps {
|
|
5
|
-
/**
|
|
6
|
-
* Background color for the placeholder. Defaults to `'transparent'`,
|
|
7
|
-
* so whatever is behind it shows through to the user.
|
|
8
|
-
*
|
|
9
|
-
* **v2.0.0:** the native SurfaceView this placeholder used to stand
|
|
10
|
-
* in for is gone — the picture is `<SimbaVideo />`, in the React
|
|
11
|
-
* tree. A non-transparent value therefore paints a backdrop *over*
|
|
12
|
-
* the picture wherever the placeholder sits in front of it.
|
|
13
|
-
*/
|
|
14
|
-
backgroundColor?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A transparent, full-size **layout placeholder**.
|
|
19
|
-
*
|
|
20
|
-
* ## v2.0.0 — what this is, and is not
|
|
21
|
-
*
|
|
22
|
-
* This component used to stand in for the native SurfaceView that mpv
|
|
23
|
-
* drew into. Back then the surface was a **sibling** of the React
|
|
24
|
-
* root — pinned to `android.R.id.content` by the library's own
|
|
25
|
-
* `PlayerActivity` — and this box reserved the screen rectangle the
|
|
26
|
-
* controls overlay was positioned against.
|
|
27
|
-
*
|
|
28
|
-
* **That arrangement is gone.** The picture is now `<SimbaVideo />`:
|
|
29
|
-
* a Fabric component (`SimbaVideoView`) inside the React tree, with
|
|
30
|
-
* React Native owning its layout, its z-order and its lifecycle.
|
|
31
|
-
* Neither the library nor a host app mounts a surface at the activity
|
|
32
|
-
* root any more — a host app's Activity says so in as many words.
|
|
33
|
-
*
|
|
34
|
-
* What is left is a transparent `flex: 1` box: a full-size rectangle
|
|
35
|
-
* for a controls overlay to anchor to. `<PlayerRoot>` renders it.
|
|
36
|
-
*
|
|
37
|
-
* Whether this component and `<PlayerRoot>` should exist at all is an
|
|
38
|
-
* open question — see `B-035` in the app's master plan. Until that is
|
|
39
|
-
* decided they stay: a published package cannot quietly drop a public
|
|
40
|
-
* export.
|
|
41
|
-
*/
|
|
42
|
-
export function PlayerSurface({
|
|
43
|
-
backgroundColor = 'transparent',
|
|
44
|
-
}: PlayerSurfaceProps): React.ReactElement {
|
|
45
|
-
return (
|
|
46
|
-
<View
|
|
47
|
-
style={[styles.surface, { backgroundColor }]}
|
|
48
|
-
accessibilityElementsHidden
|
|
49
|
-
importantForAccessibility="no-hide-descendants"
|
|
50
|
-
// Collapses any accessibility tree contribution from this
|
|
51
|
-
// placeholder; the SurfaceView on the native side is already
|
|
52
|
-
// hidden from a11y (Phase 4 sets `importantForAccessibility`
|
|
53
|
-
// to `no` on the MpvRenderView).
|
|
54
|
-
/>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const styles = StyleSheet.create({
|
|
59
|
-
surface: {
|
|
60
|
-
flex: 1,
|
|
61
|
-
},
|
|
62
|
-
});
|