react-native-video-provider 0.1.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/AuVideo.podspec +28 -0
- package/LICENSE +20 -0
- package/README.md +183 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/auvideo/AuVideoModule.kt +259 -0
- package/android/src/main/java/com/auvideo/AuVideoPackage.kt +35 -0
- package/android/src/main/java/com/auvideo/AuVideoSurfaceView.kt +40 -0
- package/android/src/main/java/com/auvideo/AuVideoSurfaceViewManager.kt +38 -0
- package/android/src/main/java/com/auvideo/PlayerCore.kt +366 -0
- package/android/src/main/java/com/auvideo/SurfaceRegistry.kt +26 -0
- package/android/src/main/res/layout/au_video_player_view.xml +10 -0
- package/ios/AuVideo.h +10 -0
- package/ios/AuVideo.mm +232 -0
- package/ios/AuVideoOrientation.swift +59 -0
- package/ios/AuVideoPlayerCore.swift +415 -0
- package/ios/AuVideoSurfaceRegistry.swift +30 -0
- package/ios/AuVideoSurfaceView.h +15 -0
- package/ios/AuVideoSurfaceView.mm +63 -0
- package/lib/module/AuVideoSurfaceNativeComponent.ts +8 -0
- package/lib/module/NativeAuVideo.js +5 -0
- package/lib/module/NativeAuVideo.js.map +1 -0
- package/lib/module/components/FloatingPlayer.js +119 -0
- package/lib/module/components/FloatingPlayer.js.map +1 -0
- package/lib/module/components/FullscreenPlayer.js +59 -0
- package/lib/module/components/FullscreenPlayer.js.map +1 -0
- package/lib/module/components/GestureOverlay.js +56 -0
- package/lib/module/components/GestureOverlay.js.map +1 -0
- package/lib/module/components/MiniPlayer.js +89 -0
- package/lib/module/components/MiniPlayer.js.map +1 -0
- package/lib/module/components/VideoControls.js +191 -0
- package/lib/module/components/VideoControls.js.map +1 -0
- package/lib/module/components/VideoPlayer.js +65 -0
- package/lib/module/components/VideoPlayer.js.map +1 -0
- package/lib/module/components/VideoSurface.js +35 -0
- package/lib/module/components/VideoSurface.js.map +1 -0
- package/lib/module/core/VideoManager.js +436 -0
- package/lib/module/core/VideoManager.js.map +1 -0
- package/lib/module/hooks/useFullscreen.js +19 -0
- package/lib/module/hooks/useFullscreen.js.map +1 -0
- package/lib/module/hooks/usePiP.js +17 -0
- package/lib/module/hooks/usePiP.js.map +1 -0
- package/lib/module/hooks/usePlayback.js +21 -0
- package/lib/module/hooks/usePlayback.js.map +1 -0
- package/lib/module/hooks/useVideo.js +17 -0
- package/lib/module/hooks/useVideo.js.map +1 -0
- package/lib/module/hooks/useVideoEvents.js +26 -0
- package/lib/module/hooks/useVideoEvents.js.map +1 -0
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/provider/VideoContext.js +14 -0
- package/lib/module/provider/VideoContext.js.map +1 -0
- package/lib/module/provider/VideoProvider.js +36 -0
- package/lib/module/provider/VideoProvider.js.map +1 -0
- package/lib/module/state/createVideoStore.js +33 -0
- package/lib/module/state/createVideoStore.js.map +1 -0
- package/lib/module/types/events.js +4 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/video.js +2 -0
- package/lib/module/types/video.js.map +1 -0
- package/lib/module/utils/Emitter.js +39 -0
- package/lib/module/utils/Emitter.js.map +1 -0
- package/lib/module/utils/formatTime.js +15 -0
- package/lib/module/utils/formatTime.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/AuVideoSurfaceNativeComponent.d.ts +8 -0
- package/lib/typescript/src/AuVideoSurfaceNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/NativeAuVideo.d.ts +85 -0
- package/lib/typescript/src/NativeAuVideo.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatingPlayer.d.ts +12 -0
- package/lib/typescript/src/components/FloatingPlayer.d.ts.map +1 -0
- package/lib/typescript/src/components/FullscreenPlayer.d.ts +12 -0
- package/lib/typescript/src/components/FullscreenPlayer.d.ts.map +1 -0
- package/lib/typescript/src/components/GestureOverlay.d.ts +14 -0
- package/lib/typescript/src/components/GestureOverlay.d.ts.map +1 -0
- package/lib/typescript/src/components/MiniPlayer.d.ts +16 -0
- package/lib/typescript/src/components/MiniPlayer.d.ts.map +1 -0
- package/lib/typescript/src/components/VideoControls.d.ts +17 -0
- package/lib/typescript/src/components/VideoControls.d.ts.map +1 -0
- package/lib/typescript/src/components/VideoPlayer.d.ts +27 -0
- package/lib/typescript/src/components/VideoPlayer.d.ts.map +1 -0
- package/lib/typescript/src/components/VideoSurface.d.ts +18 -0
- package/lib/typescript/src/components/VideoSurface.d.ts.map +1 -0
- package/lib/typescript/src/core/VideoManager.d.ts +88 -0
- package/lib/typescript/src/core/VideoManager.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useFullscreen.d.ts +7 -0
- package/lib/typescript/src/hooks/useFullscreen.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePiP.d.ts +6 -0
- package/lib/typescript/src/hooks/usePiP.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePlayback.d.ts +13 -0
- package/lib/typescript/src/hooks/usePlayback.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useVideo.d.ts +13 -0
- package/lib/typescript/src/hooks/useVideo.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useVideoEvents.d.ts +14 -0
- package/lib/typescript/src/hooks/useVideoEvents.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +18 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/provider/VideoContext.d.ts +8 -0
- package/lib/typescript/src/provider/VideoContext.d.ts.map +1 -0
- package/lib/typescript/src/provider/VideoProvider.d.ts +18 -0
- package/lib/typescript/src/provider/VideoProvider.d.ts.map +1 -0
- package/lib/typescript/src/state/createVideoStore.d.ts +6 -0
- package/lib/typescript/src/state/createVideoStore.d.ts.map +1 -0
- package/lib/typescript/src/types/events.d.ts +46 -0
- package/lib/typescript/src/types/events.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +3 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/types/video.d.ts +70 -0
- package/lib/typescript/src/types/video.d.ts.map +1 -0
- package/lib/typescript/src/utils/Emitter.d.ts +15 -0
- package/lib/typescript/src/utils/Emitter.d.ts.map +1 -0
- package/lib/typescript/src/utils/formatTime.d.ts +2 -0
- package/lib/typescript/src/utils/formatTime.d.ts.map +1 -0
- package/package.json +154 -0
- package/src/AuVideoSurfaceNativeComponent.ts +8 -0
- package/src/NativeAuVideo.ts +106 -0
- package/src/components/FloatingPlayer.tsx +130 -0
- package/src/components/FullscreenPlayer.tsx +64 -0
- package/src/components/GestureOverlay.tsx +76 -0
- package/src/components/MiniPlayer.tsx +93 -0
- package/src/components/VideoControls.tsx +213 -0
- package/src/components/VideoPlayer.tsx +77 -0
- package/src/components/VideoSurface.tsx +39 -0
- package/src/core/VideoManager.ts +441 -0
- package/src/hooks/useFullscreen.ts +14 -0
- package/src/hooks/usePiP.ts +13 -0
- package/src/hooks/usePlayback.ts +26 -0
- package/src/hooks/useVideo.ts +16 -0
- package/src/hooks/useVideoEvents.ts +33 -0
- package/src/index.ts +54 -0
- package/src/provider/VideoContext.ts +12 -0
- package/src/provider/VideoProvider.tsx +41 -0
- package/src/state/createVideoStore.ts +33 -0
- package/src/types/events.ts +22 -0
- package/src/types/index.ts +11 -0
- package/src/types/video.ts +85 -0
- package/src/utils/Emitter.ts +51 -0
- package/src/utils/formatTime.ts +12 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PlayerMode, VideoError, VideoSource } from './video';
|
|
2
|
+
|
|
3
|
+
export interface VideoEventMap {
|
|
4
|
+
onLoad: { videoId: string; duration: number; width: number; height: number };
|
|
5
|
+
onReady: { videoId: string };
|
|
6
|
+
onPlay: undefined;
|
|
7
|
+
onPause: undefined;
|
|
8
|
+
onBuffer: { buffering: boolean };
|
|
9
|
+
onSeek: { position: number };
|
|
10
|
+
onProgress: { position: number; duration: number; buffered: number };
|
|
11
|
+
onEnd: undefined;
|
|
12
|
+
onError: VideoError;
|
|
13
|
+
onEnterFullscreen: undefined;
|
|
14
|
+
onExitFullscreen: undefined;
|
|
15
|
+
onAttach: { surfaceId: string };
|
|
16
|
+
onDetach: { surfaceId: string };
|
|
17
|
+
onModeChanged: { mode: PlayerMode };
|
|
18
|
+
onVideoChanged: { video: VideoSource | null };
|
|
19
|
+
onPipChanged: { active: boolean };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type VideoEventName = keyof VideoEventMap;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export interface VideoSource {
|
|
2
|
+
/**
|
|
3
|
+
* Stable identity of the video. The engine uses this for same-video
|
|
4
|
+
* handoff: setting a source whose `id` matches the current one never
|
|
5
|
+
* reloads, rebuffers or resets position.
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
uri: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
title?: string;
|
|
11
|
+
artist?: string;
|
|
12
|
+
artworkUri?: string;
|
|
13
|
+
/** Seconds. Applied only when the item is (re)loaded. */
|
|
14
|
+
startPosition?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ResizeMode = 'contain' | 'cover' | 'stretch';
|
|
18
|
+
|
|
19
|
+
export type PlayerMode =
|
|
20
|
+
'inline' | 'fullscreen' | 'floating' | 'pip' | 'background' | 'hidden';
|
|
21
|
+
|
|
22
|
+
export type PlaybackStatus =
|
|
23
|
+
| 'idle'
|
|
24
|
+
| 'loading'
|
|
25
|
+
| 'ready'
|
|
26
|
+
| 'playing'
|
|
27
|
+
| 'paused'
|
|
28
|
+
| 'buffering'
|
|
29
|
+
| 'ended'
|
|
30
|
+
| 'error';
|
|
31
|
+
|
|
32
|
+
export interface VideoError {
|
|
33
|
+
code: string;
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface VideoState {
|
|
38
|
+
currentVideo: VideoSource | null;
|
|
39
|
+
status: PlaybackStatus;
|
|
40
|
+
playing: boolean;
|
|
41
|
+
paused: boolean;
|
|
42
|
+
buffering: boolean;
|
|
43
|
+
loading: boolean;
|
|
44
|
+
/** Seconds */
|
|
45
|
+
position: number;
|
|
46
|
+
/** Seconds. 0 until loaded. */
|
|
47
|
+
duration: number;
|
|
48
|
+
/** Seconds of buffered media ahead of position. */
|
|
49
|
+
buffered: number;
|
|
50
|
+
rate: number;
|
|
51
|
+
volume: number;
|
|
52
|
+
muted: boolean;
|
|
53
|
+
repeat: boolean;
|
|
54
|
+
resizeMode: ResizeMode;
|
|
55
|
+
fullscreen: boolean;
|
|
56
|
+
pip: boolean;
|
|
57
|
+
floating: boolean;
|
|
58
|
+
mode: PlayerMode;
|
|
59
|
+
/** Surface the player is currently requested/attached to. */
|
|
60
|
+
surfaceId: string | null;
|
|
61
|
+
videoWidth: number;
|
|
62
|
+
videoHeight: number;
|
|
63
|
+
error: VideoError | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface SetSourceOptions {
|
|
67
|
+
/** Start playing as soon as ready (or immediately on handoff). Default true. */
|
|
68
|
+
autoplay?: boolean;
|
|
69
|
+
/** Attach the player to this surface as part of setting the source. */
|
|
70
|
+
surfaceId?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface VideoProviderConfig {
|
|
74
|
+
/**
|
|
75
|
+
* Render the built-in fullscreen host (a Modal that unlocks rotation).
|
|
76
|
+
* Set false if you render your own fullscreen surface. Default true.
|
|
77
|
+
*/
|
|
78
|
+
fullscreenHost?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Render the built-in draggable floating player host. Default true.
|
|
81
|
+
*/
|
|
82
|
+
floatingHost?: boolean;
|
|
83
|
+
/** Pause playback when the active surface unmounts. Default false. */
|
|
84
|
+
pauseOnDetach?: boolean;
|
|
85
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type Listener<P> = (payload: P) => void;
|
|
2
|
+
|
|
3
|
+
export interface Subscription {
|
|
4
|
+
remove(): void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Minimal typed event emitter. Listener errors are isolated so one broken
|
|
9
|
+
* subscriber cannot break playback state propagation.
|
|
10
|
+
*/
|
|
11
|
+
export class Emitter<Events extends object> {
|
|
12
|
+
private listeners = new Map<keyof Events, Set<Listener<never>>>();
|
|
13
|
+
|
|
14
|
+
addListener<K extends keyof Events>(
|
|
15
|
+
event: K,
|
|
16
|
+
listener: Listener<Events[K]>
|
|
17
|
+
): Subscription {
|
|
18
|
+
let set = this.listeners.get(event);
|
|
19
|
+
if (!set) {
|
|
20
|
+
set = new Set();
|
|
21
|
+
this.listeners.set(event, set);
|
|
22
|
+
}
|
|
23
|
+
set.add(listener as Listener<never>);
|
|
24
|
+
return {
|
|
25
|
+
remove: () => {
|
|
26
|
+
set.delete(listener as Listener<never>);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
emit<K extends keyof Events>(event: K, payload: Events[K]): void {
|
|
32
|
+
const set = this.listeners.get(event);
|
|
33
|
+
if (!set) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const listener of Array.from(set)) {
|
|
37
|
+
try {
|
|
38
|
+
(listener as Listener<Events[K]>)(payload);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(
|
|
41
|
+
`[react-native-video-provider] listener for ${String(event)} threw`,
|
|
42
|
+
e
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
removeAll(): void {
|
|
49
|
+
this.listeners.clear();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function formatTime(totalSeconds: number): string {
|
|
2
|
+
if (!Number.isFinite(totalSeconds) || totalSeconds < 0) {
|
|
3
|
+
return '0:00';
|
|
4
|
+
}
|
|
5
|
+
const s = Math.floor(totalSeconds);
|
|
6
|
+
const hours = Math.floor(s / 3600);
|
|
7
|
+
const minutes = Math.floor((s % 3600) / 60);
|
|
8
|
+
const seconds = s % 60;
|
|
9
|
+
const mm = hours > 0 ? String(minutes).padStart(2, '0') : String(minutes);
|
|
10
|
+
const ss = String(seconds).padStart(2, '0');
|
|
11
|
+
return hours > 0 ? `${hours}:${mm}:${ss}` : `${mm}:${ss}`;
|
|
12
|
+
}
|