softbuilders-react-video-player 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -21
- package/README.md +126 -126
- package/dist/components/BigPlayButton/index.tsx +31 -31
- package/dist/components/BufferTracker/index.tsx +19 -19
- package/dist/components/ChapterTooltip/index.tsx +65 -65
- package/dist/components/ChaptersPanal/index.tsx +40 -40
- package/dist/components/ControlBar/index.d.ts +2 -1
- package/dist/components/ControlBar/index.js +19 -5
- package/dist/components/ControlBar/index.js.map +1 -1
- package/dist/components/ControlBar/index.tsx +149 -127
- package/dist/components/CreateNoteMenu/index.tsx +61 -61
- package/dist/components/CurrentTimeLabel/index.tsx +13 -13
- package/dist/components/CurrentTimeTracker/index.tsx +18 -18
- package/dist/components/Menu/index.tsx +49 -49
- package/dist/components/MenuButton/index.js +1 -1
- package/dist/components/MenuButton/index.js.map +1 -1
- package/dist/components/MenuButton/index.tsx +67 -67
- package/dist/components/NoteTooltip/index.tsx +46 -46
- package/dist/components/NotesPanal/index.tsx +34 -34
- package/dist/components/QualityMenu/index.js +2 -2
- package/dist/components/QualityMenu/index.js.map +1 -1
- package/dist/components/QualityMenu/index.tsx +122 -122
- package/dist/components/Slider/index.d.ts +1 -1
- package/dist/components/Slider/index.js +3 -3
- package/dist/components/Slider/index.js.map +1 -1
- package/dist/components/Slider/index.tsx +36 -37
- package/dist/components/Slider/style.css +49 -15
- package/dist/components/SoftBuildersVideoPlayer/index.js +1 -1
- package/dist/components/SoftBuildersVideoPlayer/index.js.map +1 -1
- package/dist/components/SoftBuildersVideoPlayer/index.tsx +110 -109
- package/dist/components/SubtitleMenu/index.js +2 -2
- package/dist/components/SubtitleMenu/index.js.map +1 -1
- package/dist/components/SubtitleMenu/index.tsx +107 -108
- package/dist/components/TimeSlider/index.js +13 -13
- package/dist/components/TimeSlider/index.tsx +107 -107
- package/dist/components/TimeSliderContainer/index.tsx +35 -35
- package/dist/components/Tooltip/index.tsx +16 -16
- package/dist/components/VideoPlayerComponent/index.d.ts +2 -1
- package/dist/components/VideoPlayerComponent/index.js +38 -36
- package/dist/components/VideoPlayerComponent/index.js.map +1 -1
- package/dist/components/VideoPlayerComponent/index.tsx +260 -249
- package/dist/components/VideoPlayerComponent/provider.tsx +82 -82
- package/dist/components/VideoPlayerComponent/style/style.css +36 -36
- package/dist/components/VolumeSlider/index.d.ts +4 -2
- package/dist/components/VolumeSlider/index.js +12 -2
- package/dist/components/VolumeSlider/index.js.map +1 -1
- package/dist/components/VolumeSlider/index.tsx +91 -52
- package/dist/components/icons/SubIcon.d.ts +3 -0
- package/dist/components/icons/SubIcon.js +4 -0
- package/dist/components/icons/SubIcon.js.map +1 -0
- package/dist/components/icons/SubIcon.tsx +28 -0
- package/dist/components/icons/index.d.ts +1 -0
- package/dist/components/icons/index.js +1 -0
- package/dist/components/icons/index.js.map +1 -1
- package/dist/components/icons/index.ts +15 -14
- package/dist/images/index.d.ts +1 -0
- package/dist/images/index.js +1 -0
- package/dist/images/index.js.map +1 -1
- package/dist/index.css +75 -3
- package/dist/index.mjs +253 -166
- package/dist/styles/tailwind.css +137 -87
- package/package.json +45 -45
@@ -1,249 +1,260 @@
|
|
1
|
-
import React, { useEffect, useRef, useState } from "react";
|
2
|
-
import ReactDOM from "react-dom/client";
|
3
|
-
import videojs from "video.js";
|
4
|
-
import Player from "video.js/dist/types/player";
|
5
|
-
import "video.js/dist/video-js.css";
|
6
|
-
import ControlBar from "../ControlBar";
|
7
|
-
import {
|
8
|
-
SoftBuildersVideoPlayerChapter,
|
9
|
-
SoftBuildersVideoPlayerNote,
|
10
|
-
SoftBuildersVideoPlayerOptions,
|
11
|
-
} from "../../types";
|
12
|
-
|
13
|
-
import "./style/style.css";
|
14
|
-
import "../../styles/tailwind.css";
|
15
|
-
import { SoftBuildersVideoPlayerProvider } from "./provider";
|
16
|
-
import BigPlayButton from "../BigPlayButton";
|
17
|
-
|
18
|
-
let bigPlayButtonRoot: {
|
19
|
-
[key: string]: ReactDOM.Root | undefined;
|
20
|
-
} = {};
|
21
|
-
|
22
|
-
const renderBigPlayButton = (
|
23
|
-
id: string,
|
24
|
-
player: Player | undefined,
|
25
|
-
isPaused: boolean,
|
26
|
-
setIsPaused: React.Dispatch<React.SetStateAction<boolean>>
|
27
|
-
) => {
|
28
|
-
const container = document.getElementById(`video-container-${id}`);
|
29
|
-
if (container) {
|
30
|
-
const element: any = container.querySelector(".vjs-big-play-button");
|
31
|
-
if (element) {
|
32
|
-
if (!bigPlayButtonRoot[id]) {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if (container) {
|
65
|
-
const element: any = container.querySelector(".vjs-control-bar");
|
66
|
-
if (element) {
|
67
|
-
if (!controlBarRoot[id]) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
element.style.
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
const
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
});
|
132
|
-
|
133
|
-
player.on("
|
134
|
-
|
135
|
-
|
136
|
-
});
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
2
|
+
import ReactDOM from "react-dom/client";
|
3
|
+
import videojs from "video.js";
|
4
|
+
import Player from "video.js/dist/types/player";
|
5
|
+
import "video.js/dist/video-js.css";
|
6
|
+
import ControlBar from "../ControlBar";
|
7
|
+
import {
|
8
|
+
SoftBuildersVideoPlayerChapter,
|
9
|
+
SoftBuildersVideoPlayerNote,
|
10
|
+
SoftBuildersVideoPlayerOptions,
|
11
|
+
} from "../../types";
|
12
|
+
|
13
|
+
import "./style/style.css";
|
14
|
+
import "../../styles/tailwind.css";
|
15
|
+
import { SoftBuildersVideoPlayerProvider } from "./provider";
|
16
|
+
import BigPlayButton from "../BigPlayButton";
|
17
|
+
|
18
|
+
let bigPlayButtonRoot: {
|
19
|
+
[key: string]: ReactDOM.Root | undefined;
|
20
|
+
} = {};
|
21
|
+
|
22
|
+
const renderBigPlayButton = (
|
23
|
+
id: string,
|
24
|
+
player: Player | undefined,
|
25
|
+
isPaused: boolean,
|
26
|
+
setIsPaused: React.Dispatch<React.SetStateAction<boolean>>
|
27
|
+
) => {
|
28
|
+
const container = document.getElementById(`video-container-${id}`);
|
29
|
+
if (container) {
|
30
|
+
const element: any = container.querySelector(".vjs-big-play-button");
|
31
|
+
if (element) {
|
32
|
+
if (!bigPlayButtonRoot[id]) {
|
33
|
+
bigPlayButtonRoot[id] = ReactDOM.createRoot(element as HTMLElement);
|
34
|
+
}
|
35
|
+
|
36
|
+
bigPlayButtonRoot[id].render(
|
37
|
+
<BigPlayButton
|
38
|
+
player={player}
|
39
|
+
isPaused={isPaused}
|
40
|
+
setIsPaused={setIsPaused}
|
41
|
+
/>
|
42
|
+
);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
let controlBarRoot: {
|
48
|
+
[key: string]: ReactDOM.Root | undefined;
|
49
|
+
} = {};
|
50
|
+
|
51
|
+
const renderControlBar = <T,>(
|
52
|
+
id: string,
|
53
|
+
player: Player | undefined,
|
54
|
+
isPaused: boolean,
|
55
|
+
setIsPaused: React.Dispatch<React.SetStateAction<boolean>>,
|
56
|
+
duration: number,
|
57
|
+
notes: SoftBuildersVideoPlayerNote[],
|
58
|
+
chapters: SoftBuildersVideoPlayerChapter[],
|
59
|
+
seekStep: number = 5,
|
60
|
+
handleSaveNoteAction?: (time: number, note: string) => Promise<T>
|
61
|
+
) => {
|
62
|
+
const container = document.getElementById(`video-container-${id}`);
|
63
|
+
|
64
|
+
if (container) {
|
65
|
+
const element: any = container.querySelector(".vjs-control-bar");
|
66
|
+
if (element) {
|
67
|
+
if (!controlBarRoot[id]) {
|
68
|
+
controlBarRoot[id] = ReactDOM.createRoot(element as HTMLElement);
|
69
|
+
}
|
70
|
+
|
71
|
+
element.style.display = "flex";
|
72
|
+
element.style.height = "100%";
|
73
|
+
element.style.alignItems = "flex-end";
|
74
|
+
controlBarRoot[id].render(
|
75
|
+
<SoftBuildersVideoPlayerProvider>
|
76
|
+
<ControlBar
|
77
|
+
id={id}
|
78
|
+
player={player}
|
79
|
+
isPaused={isPaused}
|
80
|
+
setIsPaused={setIsPaused}
|
81
|
+
duration={duration}
|
82
|
+
notes={notes}
|
83
|
+
chapters={chapters}
|
84
|
+
seekStep={seekStep}
|
85
|
+
handleSaveNoteAction={handleSaveNoteAction}
|
86
|
+
/>
|
87
|
+
</SoftBuildersVideoPlayerProvider>
|
88
|
+
);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
export type Props<T = any> = {
|
94
|
+
id: string;
|
95
|
+
options: SoftBuildersVideoPlayerOptions;
|
96
|
+
notes: SoftBuildersVideoPlayerNote[];
|
97
|
+
chapters: SoftBuildersVideoPlayerChapter[];
|
98
|
+
startTime?: number;
|
99
|
+
poster?: string; // Changed to string type for poster URL
|
100
|
+
handleSaveNoteAction?: (time: number, note: string) => Promise<T>;
|
101
|
+
onPlay?: (time: number) => void;
|
102
|
+
onPause?: (time: number) => void;
|
103
|
+
};
|
104
|
+
|
105
|
+
const VideoPlayerComponent = <T,>({
|
106
|
+
id,
|
107
|
+
options,
|
108
|
+
notes,
|
109
|
+
chapters,
|
110
|
+
startTime = 0,
|
111
|
+
handleSaveNoteAction,
|
112
|
+
poster,
|
113
|
+
|
114
|
+
onPlay,
|
115
|
+
onPause,
|
116
|
+
}: Props<T>) => {
|
117
|
+
const videoRef = useRef<any>(undefined);
|
118
|
+
const playerRef = useRef<Player | undefined>(undefined);
|
119
|
+
|
120
|
+
const [isReady, setIsReady] = useState(false);
|
121
|
+
const [isPaused, setIsPaused] = useState(!options.autoplay);
|
122
|
+
const [duration, setDuratoin] = useState(1);
|
123
|
+
|
124
|
+
const onReady = (player: Player) => {
|
125
|
+
if (playerRef) {
|
126
|
+
playerRef.current = player;
|
127
|
+
setIsReady(true);
|
128
|
+
|
129
|
+
player.currentTime(startTime);
|
130
|
+
|
131
|
+
player.on("waiting", () => {});
|
132
|
+
|
133
|
+
player.on("dispose", () => {
|
134
|
+
videojs.log("player will dispose");
|
135
|
+
setIsReady(false);
|
136
|
+
});
|
137
|
+
|
138
|
+
player.on("loadedmetadata", () => {
|
139
|
+
const d = player.duration() || 0;
|
140
|
+
setDuratoin(d);
|
141
|
+
});
|
142
|
+
}
|
143
|
+
};
|
144
|
+
|
145
|
+
useEffect(() => {
|
146
|
+
if (!playerRef.current) {
|
147
|
+
const videoElement = document.createElement("video-js");
|
148
|
+
videoElement.classList.add("vjs-big-play-centered");
|
149
|
+
// Set the poster attribute here
|
150
|
+
|
151
|
+
if (poster) {
|
152
|
+
videoElement.setAttribute("poster", poster);
|
153
|
+
}
|
154
|
+
videoRef.current.appendChild(videoElement);
|
155
|
+
|
156
|
+
playerRef.current = videojs(videoElement, options, () => {
|
157
|
+
onReady(playerRef.current as Player);
|
158
|
+
});
|
159
|
+
}
|
160
|
+
|
161
|
+
return () => {
|
162
|
+
if (playerRef.current) {
|
163
|
+
playerRef.current.dispose();
|
164
|
+
playerRef.current = undefined;
|
165
|
+
|
166
|
+
setTimeout(() => {
|
167
|
+
if (bigPlayButtonRoot[id]) {
|
168
|
+
bigPlayButtonRoot[id].unmount();
|
169
|
+
bigPlayButtonRoot[id] = undefined;
|
170
|
+
}
|
171
|
+
if (controlBarRoot[id]) {
|
172
|
+
controlBarRoot[id].unmount();
|
173
|
+
controlBarRoot[id] = undefined;
|
174
|
+
}
|
175
|
+
}, 0);
|
176
|
+
}
|
177
|
+
};
|
178
|
+
}, [options, poster]); // Added poster to dependency array
|
179
|
+
|
180
|
+
useEffect(() => {
|
181
|
+
if (playerRef.current && isReady) {
|
182
|
+
const currentTime = playerRef.current.currentTime() || 0;
|
183
|
+
|
184
|
+
if (isPaused) {
|
185
|
+
if (onPause) onPause(currentTime);
|
186
|
+
} else {
|
187
|
+
if (onPlay) onPlay(currentTime);
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}, [isPaused, isReady]);
|
191
|
+
|
192
|
+
useEffect(() => {
|
193
|
+
if (isReady) {
|
194
|
+
const controlBarTimeout = setTimeout(() => {
|
195
|
+
renderControlBar(
|
196
|
+
id,
|
197
|
+
playerRef.current,
|
198
|
+
isPaused,
|
199
|
+
setIsPaused,
|
200
|
+
duration,
|
201
|
+
notes,
|
202
|
+
chapters,
|
203
|
+
5,
|
204
|
+
handleSaveNoteAction
|
205
|
+
);
|
206
|
+
}, 500);
|
207
|
+
|
208
|
+
return () => clearTimeout(controlBarTimeout);
|
209
|
+
}
|
210
|
+
}, [
|
211
|
+
id,
|
212
|
+
playerRef,
|
213
|
+
isPaused,
|
214
|
+
setIsPaused,
|
215
|
+
notes,
|
216
|
+
chapters,
|
217
|
+
isReady,
|
218
|
+
handleSaveNoteAction,
|
219
|
+
duration,
|
220
|
+
]);
|
221
|
+
|
222
|
+
useEffect(() => {
|
223
|
+
if (isReady) {
|
224
|
+
const playButtonTimeout = setTimeout(() => {
|
225
|
+
renderBigPlayButton(id, playerRef.current, isPaused, setIsPaused);
|
226
|
+
}, 500);
|
227
|
+
|
228
|
+
return () => clearTimeout(playButtonTimeout);
|
229
|
+
}
|
230
|
+
}, [id, isPaused, isReady]);
|
231
|
+
|
232
|
+
useEffect(() => {
|
233
|
+
if (playerRef.current) {
|
234
|
+
const intervalId = setInterval(() => {
|
235
|
+
if (playerRef.current) setIsPaused(playerRef.current.paused());
|
236
|
+
}, 500);
|
237
|
+
|
238
|
+
return () => clearInterval(intervalId);
|
239
|
+
}
|
240
|
+
}, []);
|
241
|
+
|
242
|
+
return (
|
243
|
+
<div
|
244
|
+
id={`video-container-${id}`}
|
245
|
+
className="sb-relative sb-rounded-md sb-overflow-hidden"
|
246
|
+
>
|
247
|
+
<div
|
248
|
+
data-vjs-player
|
249
|
+
style={{
|
250
|
+
height: "100%", // Adjust height as needed
|
251
|
+
position: "relative",
|
252
|
+
}}
|
253
|
+
>
|
254
|
+
<div ref={videoRef} />
|
255
|
+
</div>
|
256
|
+
</div>
|
257
|
+
);
|
258
|
+
};
|
259
|
+
|
260
|
+
export default VideoPlayerComponent;
|