softbuilders-react-video-player 1.3.2 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -140,88 +140,141 @@ export type Props<T = any> = {
140
140
  isTrailer?: boolean;
141
141
  height?: number;
142
142
  };
143
- const VideoPlayerComponent = forwardRef<HTMLDivElement, Props<any>>(
144
- (
145
- {
146
- id,
147
- options,
148
- notes,
149
- chapters,
150
- startTime = 0,
151
- handleSaveNoteAction,
152
- poster,
153
- onPlay,
154
- onPause,
155
- disableNote,
156
- childRef,
157
- bottomRedBar = true,
158
- noteButtonClick,
159
- videoID,
160
- isTrailer,
161
- height,
162
- }: Props,
163
- ref: any
164
- ) => {
165
- const videoRef = useRef<any>(undefined);
166
- const playerRef = useRef<Player | undefined>(undefined);
167
- const idRef = useRef<any | undefined>(undefined);
168
-
169
- const [isReady, setIsReady] = useState(false);
170
- const [isPaused, setIsPaused] = useState(!options.autoplay);
171
- const [duration, setDuration] = useState(1);
172
- const [opacity, setOpacity] = useState("0");
173
- const [isControlBarPresent, setIsControlBarPresent] = useState(true);
174
- const [bgColor, setBgColor] = useState("transparent");
175
- const [isQualityMenuOpen, setIsQualityMenuOpen] = useState(false);
176
- const [isSubtitleMenuOpen, setIsSubtitleMenuOpen] = useState(false);
177
- const [isHovered, setIsHovered] = useState(false);
178
- const [isNoteOpen, setNoteOpen] = useState(false);
179
- const [heightValue, setHeightValue] = useState<number>(0);
180
- const [isLoading, setIsloading] = useState<boolean>(false);
181
-
182
- const onReady = (player: Player) => {
183
- if (playerRef) {
184
- playerRef.current = player;
185
- setIsReady(true);
186
-
187
- player?.currentTime(startTime);
188
-
189
- player.on("waiting", () => {});
190
- player.on("dispose", () => {
191
- videojs.log("player will dispose");
192
- setIsReady(false);
193
- });
194
- player.on("loadedmetadata", () => {
195
- const d = player.duration() || 0;
196
- setDuration(d);
197
- });
143
+ const VideoPlayerComponent = ({
144
+ id,
145
+ options,
146
+ notes,
147
+ chapters,
148
+ startTime = 0,
149
+ handleSaveNoteAction,
150
+ poster,
151
+ onPlay,
152
+ onPause,
153
+ disableNote,
154
+ childRef,
155
+ bottomRedBar = true,
156
+ noteButtonClick,
157
+ videoID,
158
+ isTrailer,
159
+ height,
160
+ }: Props) => {
161
+ const videoRef = useRef<any>(undefined);
162
+ const playerRef = useRef<Player | undefined>(undefined);
163
+ const idRef = useRef<any | undefined>(undefined);
164
+
165
+ const [isReady, setIsReady] = useState(false);
166
+ const [isPaused, setIsPaused] = useState(!options.autoplay);
167
+ const [duration, setDuration] = useState(1);
168
+ const [opacity, setOpacity] = useState("0");
169
+ const [isControlBarPresent, setIsControlBarPresent] = useState(true);
170
+ const [bgColor, setBgColor] = useState("transparent");
171
+ const [isQualityMenuOpen, setIsQualityMenuOpen] = useState(false);
172
+ const [isSubtitleMenuOpen, setIsSubtitleMenuOpen] = useState(false);
173
+ const [isHovered, setIsHovered] = useState(false);
174
+ const [isNoteOpen, setNoteOpen] = useState(false);
175
+ const [heightValue, setHeightValue] = useState<number>(0);
176
+ const [isLoading, setIsloading] = useState<boolean>(false);
177
+
178
+ const onReady = (player: Player) => {
179
+ if (playerRef) {
180
+ playerRef.current = player;
181
+ setIsReady(true);
182
+
183
+ player?.currentTime(startTime);
184
+
185
+ player.on("waiting", () => {});
186
+ player.on("dispose", () => {
187
+ videojs.log("player will dispose");
188
+ setIsReady(false);
189
+ });
190
+ player.on("loadedmetadata", () => {
191
+ const d = player.duration() || 0;
192
+ setDuration(d);
193
+ });
194
+ }
195
+ };
196
+ useEffect(() => {
197
+ if (!playerRef.current) {
198
+ const videoElement = document.createElement("video-js");
199
+
200
+ videoElement.setAttribute("playsinline", "true");
201
+
202
+ videoElement.classList.add("vjs-big-play-centered");
203
+ // Set the poster attribute here
204
+ if (poster) {
205
+ videoElement.setAttribute("poster", poster);
206
+ }
207
+ videoRef.current.appendChild(videoElement);
208
+ videoElement.style.width = "100%";
209
+ videoElement.style.height = "100%";
210
+ videoElement.style.objectFit = "cover";
211
+ playerRef.current = videojs(videoElement, options, () => {
212
+ onReady(playerRef.current as Player);
213
+ });
214
+ }
215
+ return () => {
216
+ if (playerRef.current) {
217
+ idRef.current = options;
218
+ playerRef.current.dispose();
219
+ playerRef.current = undefined;
220
+
221
+ setTimeout(() => {
222
+ if (bigPlayButtonRoot[id]) {
223
+ bigPlayButtonRoot[id].unmount();
224
+ bigPlayButtonRoot[id] = undefined;
225
+ }
226
+ if (controlBarRoot[id]) {
227
+ controlBarRoot[id].unmount();
228
+ controlBarRoot[id] = undefined;
229
+ }
230
+ }, 0);
231
+
232
+ // setTimeout(() => {
233
+ // if (bigPlayButtonRoot[id]) {
234
+ // bigPlayButtonRoot[id].unmount();
235
+ // bigPlayButtonRoot[id] = undefined;
236
+ // }
237
+ // if (controlBarRoot[id]) {
238
+ // controlBarRoot[id].unmount();
239
+ // controlBarRoot[id] = undefined;
240
+ // }
241
+ // }, 0);
198
242
  }
199
243
  };
200
- useEffect(() => {
201
- if (!playerRef.current) {
202
- const videoElement = document.createElement("video-js");
244
+ }, [id]);
203
245
 
204
- videoElement.setAttribute("playsinline", "true");
246
+ useEffect(() => {
247
+ if (playerRef.current) {
248
+ const myPlayer = playerRef.current.currentSources();
249
+ playerRef.current.src(options.sources);
250
+ playerRef.current.load();
251
+ }
252
+ }, [options.sources[0].type]);
253
+ useEffect(() => {
254
+ if (!playerRef.current) {
255
+ const videoElement = document.createElement("video-js");
205
256
 
206
- videoElement.classList.add("vjs-big-play-centered");
207
- // Set the poster attribute here
208
- if (poster) {
209
- videoElement.setAttribute("poster", poster);
210
- }
211
- videoRef.current.appendChild(videoElement);
212
- videoElement.style.width = "100%";
213
- videoElement.style.height = "100%";
214
- videoElement.style.objectFit = "cover";
215
- playerRef.current = videojs(videoElement, options, () => {
216
- onReady(playerRef.current as Player);
217
- });
257
+ videoElement.setAttribute("playsinline", "true");
258
+
259
+ videoElement.classList.add("vjs-big-play-centered");
260
+ // Set the poster attribute here
261
+ if (poster) {
262
+ videoElement.setAttribute("poster", poster);
218
263
  }
219
- return () => {
220
- if (playerRef.current) {
264
+ videoRef.current.appendChild(videoElement);
265
+ videoElement.style.width = "100%";
266
+ videoElement.style.height = "100%";
267
+ videoElement.style.objectFit = "cover";
268
+ playerRef.current = videojs(videoElement, options, () => {
269
+ onReady(playerRef.current as Player);
270
+ });
271
+ }
272
+ return () => {
273
+ if (playerRef.current) {
274
+ if (!isEqual(idRef?.current?.sources ?? "", options.sources)) {
221
275
  idRef.current = options;
222
276
  playerRef.current.dispose();
223
277
  playerRef.current = undefined;
224
-
225
278
  setTimeout(() => {
226
279
  if (bigPlayButtonRoot[id]) {
227
280
  bigPlayButtonRoot[id].unmount();
@@ -232,386 +285,329 @@ const VideoPlayerComponent = forwardRef<HTMLDivElement, Props<any>>(
232
285
  controlBarRoot[id] = undefined;
233
286
  }
234
287
  }, 0);
235
-
236
- // setTimeout(() => {
237
- // if (bigPlayButtonRoot[id]) {
238
- // bigPlayButtonRoot[id].unmount();
239
- // bigPlayButtonRoot[id] = undefined;
240
- // }
241
- // if (controlBarRoot[id]) {
242
- // controlBarRoot[id].unmount();
243
- // controlBarRoot[id] = undefined;
244
- // }
245
- // }, 0);
246
288
  }
247
- };
248
- }, [id]);
249
-
250
- useEffect(() => {
251
- if (playerRef.current) {
252
- const myPlayer = playerRef.current.currentSources();
253
- playerRef.current.src(options.sources);
254
- playerRef.current.load();
255
- }
256
- }, [options.sources[0].type]);
257
- useEffect(() => {
258
- if (!playerRef.current) {
259
- const videoElement = document.createElement("video-js");
260
-
261
- videoElement.setAttribute("playsinline", "true");
262
289
 
263
- videoElement.classList.add("vjs-big-play-centered");
264
- // Set the poster attribute here
265
- if (poster) {
266
- videoElement.setAttribute("poster", poster);
267
- }
268
- videoRef.current.appendChild(videoElement);
269
- videoElement.style.width = "100%";
270
- videoElement.style.height = "100%";
271
- videoElement.style.objectFit = "cover";
272
- playerRef.current = videojs(videoElement, options, () => {
273
- onReady(playerRef.current as Player);
274
- });
290
+ // setTimeout(() => {
291
+ // if (bigPlayButtonRoot[id]) {
292
+ // bigPlayButtonRoot[id].unmount();
293
+ // bigPlayButtonRoot[id] = undefined;
294
+ // }
295
+ // if (controlBarRoot[id]) {
296
+ // controlBarRoot[id].unmount();
297
+ // controlBarRoot[id] = undefined;
298
+ // }
299
+ // }, 0);
275
300
  }
276
- return () => {
277
- if (playerRef.current) {
278
- if (!isEqual(idRef?.current?.sources ?? "", options.sources)) {
279
- idRef.current = options;
280
- playerRef.current.dispose();
281
- playerRef.current = undefined;
282
- setTimeout(() => {
283
- if (bigPlayButtonRoot[id]) {
284
- bigPlayButtonRoot[id].unmount();
285
- bigPlayButtonRoot[id] = undefined;
286
- }
287
- if (controlBarRoot[id]) {
288
- controlBarRoot[id].unmount();
289
- controlBarRoot[id] = undefined;
290
- }
291
- }, 0);
292
- }
293
-
294
- // setTimeout(() => {
295
- // if (bigPlayButtonRoot[id]) {
296
- // bigPlayButtonRoot[id].unmount();
297
- // bigPlayButtonRoot[id] = undefined;
298
- // }
299
- // if (controlBarRoot[id]) {
300
- // controlBarRoot[id].unmount();
301
- // controlBarRoot[id] = undefined;
302
- // }
303
- // }, 0);
304
- }
305
- };
306
- }, [options]);
307
- // Added poster to dependency array
301
+ };
302
+ }, [options]);
303
+ // Added poster to dependency array
308
304
 
309
- useEffect(() => {
310
- if (playerRef.current) {
311
- playerRef.current.currentTime(startTime);
312
- }
313
- }, [startTime]);
314
- useEffect(() => {
315
- if (playerRef.current && isReady) {
316
- const currentTime = playerRef.current.currentTime() || 0;
317
- if (isPaused) {
318
- if (onPause) onPause(currentTime);
319
- } else {
320
- if (onPlay) onPlay(currentTime);
321
- }
305
+ useEffect(() => {
306
+ if (playerRef.current) {
307
+ playerRef.current.currentTime(startTime);
308
+ }
309
+ }, [startTime]);
310
+ useEffect(() => {
311
+ if (playerRef.current && isReady) {
312
+ const currentTime = playerRef.current.currentTime() || 0;
313
+ if (isPaused) {
314
+ if (onPause) onPause(currentTime);
315
+ } else {
316
+ if (onPlay) onPlay(currentTime);
322
317
  }
323
- }, [isPaused]);
324
-
325
- useEffect(() => {
326
- const controlBarTimeout = setTimeout(() => {
327
- renderControlBar(
318
+ }
319
+ }, [isPaused]);
320
+
321
+ useEffect(() => {
322
+ const controlBarTimeout = setTimeout(() => {
323
+ renderControlBar(
324
+ id,
325
+ playerRef.current,
326
+ isPaused,
327
+ setIsPaused,
328
+ duration,
329
+ notes,
330
+ chapters,
331
+ 5,
332
+ handleSaveNoteAction,
333
+ opacity,
334
+ (e: any) => {
335
+ handlePlayerClick(e, true);
336
+ },
337
+ bgColor,
338
+ setIsQualityMenuOpen,
339
+ setIsSubtitleMenuOpen,
340
+ disableNote,
341
+ setNoteOpen,
342
+ noteButtonClick,
343
+ isTrailer
344
+ );
345
+ }, 0);
346
+ return () => clearTimeout(controlBarTimeout);
347
+ }, [
348
+ isPaused,
349
+ setIsPaused,
350
+ notes,
351
+ handleSaveNoteAction,
352
+ duration,
353
+ opacity,
354
+ isReady,
355
+ id,
356
+ playerRef?.current?.isFullscreen_,
357
+ ]);
358
+ useEffect(() => {
359
+ if (isReady) {
360
+ const playButtonTimeout = setTimeout(() => {
361
+ renderBigPlayButton(
328
362
  id,
329
363
  playerRef.current,
330
364
  isPaused,
331
365
  setIsPaused,
332
- duration,
333
- notes,
334
- chapters,
335
- 5,
336
- handleSaveNoteAction,
337
366
  opacity,
338
- (e: any) => {
339
- handlePlayerClick(e, true);
340
- },
341
- bgColor,
342
- setIsQualityMenuOpen,
343
- setIsSubtitleMenuOpen,
344
- disableNote,
345
- setNoteOpen,
346
- noteButtonClick,
347
- isTrailer
367
+ height,
368
+ heightValue,
369
+ isLoading
348
370
  );
349
- }, 0);
350
- return () => clearTimeout(controlBarTimeout);
351
- }, [
352
- isPaused,
353
- setIsPaused,
354
- notes,
355
- handleSaveNoteAction,
356
- duration,
357
- opacity,
358
- isReady,
359
- id,
360
- playerRef?.current?.isFullscreen_,
361
- ]);
362
- useEffect(() => {
363
- if (isReady) {
364
- const playButtonTimeout = setTimeout(() => {
365
- renderBigPlayButton(
366
- id,
367
- playerRef.current,
368
- isPaused,
369
- setIsPaused,
370
- opacity,
371
- height,
372
- heightValue,
373
- isLoading
374
- );
375
- }, 500);
376
- return () => clearTimeout(playButtonTimeout);
377
- }
378
- }, [isPaused, opacity, isReady, id, height, heightValue, isLoading]);
379
- useEffect(() => {
380
- if (playerRef.current) {
381
- const intervalId = setInterval(() => {
382
- if (playerRef.current) setIsPaused(playerRef.current.paused());
383
- }, 500);
384
- return () => clearInterval(intervalId);
371
+ }, 500);
372
+ return () => clearTimeout(playButtonTimeout);
373
+ }
374
+ }, [isPaused, opacity, isReady, id, height, heightValue, isLoading]);
375
+ useEffect(() => {
376
+ if (playerRef.current) {
377
+ const intervalId = setInterval(() => {
378
+ if (playerRef.current) setIsPaused(playerRef.current.paused());
379
+ }, 500);
380
+ return () => clearInterval(intervalId);
381
+ }
382
+ }, []);
383
+ // useEffect(() => {
384
+ // return () => {
385
+ // if (playerRef.current) {
386
+ // playerRef.current.dispose();
387
+ // playerRef.current = undefined;
388
+ // // Cleanup play button and control bar renders
389
+ // if (bigPlayButtonRoot[id]) {
390
+ // bigPlayButtonRoot[id].unmount();
391
+ // bigPlayButtonRoot[id] = undefined;
392
+ // }
393
+ // if (controlBarRoot[id]) {
394
+ // controlBarRoot[id].unmount();
395
+ // controlBarRoot[id] = undefined;
396
+ // }
397
+ // }
398
+ // };
399
+ // }, []);
400
+ const timeoutRef = useRef<any>(null);
401
+ useEffect(() => {
402
+ if (isQualityMenuOpen || isSubtitleMenuOpen) {
403
+ if (timeoutRef.current) {
404
+ clearTimeout(timeoutRef.current);
385
405
  }
386
- }, []);
387
- // useEffect(() => {
388
- // return () => {
389
- // if (playerRef.current) {
390
- // playerRef.current.dispose();
391
- // playerRef.current = undefined;
392
- // // Cleanup play button and control bar renders
393
- // if (bigPlayButtonRoot[id]) {
394
- // bigPlayButtonRoot[id].unmount();
395
- // bigPlayButtonRoot[id] = undefined;
396
- // }
397
- // if (controlBarRoot[id]) {
398
- // controlBarRoot[id].unmount();
399
- // controlBarRoot[id] = undefined;
400
- // }
401
- // }
402
- // };
403
- // }, []);
404
- const timeoutRef = useRef<any>(null);
405
- useEffect(() => {
406
- if (isQualityMenuOpen || isSubtitleMenuOpen) {
407
- if (timeoutRef.current) {
408
- clearTimeout(timeoutRef.current);
409
- }
410
- setOpacity("100");
411
- } else {
412
- if (timeoutRef.current) {
413
- clearTimeout(timeoutRef.current);
414
- }
415
- setOpacity("0");
416
-
417
- timeoutRef.current = setTimeout(() => {
418
- setIsControlBarPresent(false);
419
- }, 3000);
406
+ setOpacity("100");
407
+ } else {
408
+ if (timeoutRef.current) {
409
+ clearTimeout(timeoutRef.current);
420
410
  }
421
- }, [isQualityMenuOpen, isSubtitleMenuOpen]);
422
- useEffect(() => {
423
- if (isNoteOpen) {
424
- if (timeoutRef.current) {
425
- clearTimeout(timeoutRef.current);
426
- }
427
- } else {
428
- if (timeoutRef.current) {
429
- clearTimeout(timeoutRef.current);
430
- }
411
+ setOpacity("0");
431
412
 
432
- timeoutRef.current = setTimeout(() => {
433
- setIsControlBarPresent(false);
434
- }, 3000);
413
+ timeoutRef.current = setTimeout(() => {
414
+ setIsControlBarPresent(false);
415
+ }, 3000);
416
+ }
417
+ }, [isQualityMenuOpen, isSubtitleMenuOpen]);
418
+ useEffect(() => {
419
+ if (isNoteOpen) {
420
+ if (timeoutRef.current) {
421
+ clearTimeout(timeoutRef.current);
435
422
  }
436
- }, [isNoteOpen]);
437
-
438
- const handlePlayerClick = async (e: any, isTimerOnly = false) => {
439
- e.preventDefault();
423
+ } else {
440
424
  if (timeoutRef.current) {
441
425
  clearTimeout(timeoutRef.current);
442
426
  }
443
- setOpacity("100");
444
- setIsControlBarPresent(true);
445
- // setBgColor("rgba(200, 200, 200, 0.5)");
446
- // not using now
427
+
447
428
  timeoutRef.current = setTimeout(() => {
448
- setOpacity("0");
449
- setBgColor("transparent");
450
429
  setIsControlBarPresent(false);
451
430
  }, 3000);
452
- if (isTimerOnly) {
453
- return;
454
- }
455
- if (!isControlBarPresent) {
456
- return;
457
- }
458
- if (playerRef.current) {
459
- if (playerRef.current.paused()) {
460
- try {
461
- await playerRef.current.play();
462
- setIsPaused(false);
463
- } catch (error) {
464
- console.error("Failed to play video:", error);
465
- }
466
- } else {
467
- playerRef.current.pause();
468
- setIsPaused(true);
469
- if (onPause) onPause(playerRef.current.currentTime() || 0);
431
+ }
432
+ }, [isNoteOpen]);
433
+
434
+ const handlePlayerClick = async (e: any, isTimerOnly = false) => {
435
+ e.preventDefault();
436
+ if (timeoutRef.current) {
437
+ clearTimeout(timeoutRef.current);
438
+ }
439
+ setOpacity("100");
440
+ setIsControlBarPresent(true);
441
+ // setBgColor("rgba(200, 200, 200, 0.5)");
442
+ // not using now
443
+ timeoutRef.current = setTimeout(() => {
444
+ setOpacity("0");
445
+ setBgColor("transparent");
446
+ setIsControlBarPresent(false);
447
+ }, 3000);
448
+ if (isTimerOnly) {
449
+ return;
450
+ }
451
+ if (!isControlBarPresent) {
452
+ return;
453
+ }
454
+ if (playerRef.current) {
455
+ if (playerRef.current.paused()) {
456
+ try {
457
+ await playerRef.current.play();
458
+ setIsPaused(false);
459
+ } catch (error) {
460
+ console.error("Failed to play video:", error);
470
461
  }
462
+ } else {
463
+ playerRef.current.pause();
464
+ setIsPaused(true);
465
+ if (onPause) onPause(playerRef.current.currentTime() || 0);
471
466
  }
472
- };
473
- const videoRefs = useRef<HTMLDivElement>(null); // Create a reference for the element
474
-
475
- useEffect(() => {
476
- const observer = new IntersectionObserver(
477
- (entries) => {
478
- entries.forEach((entry) => {
479
- if (entry.isIntersecting === false) {
480
- if (playerRef?.current?.paused() === false) {
481
- try {
482
- playerRef?.current?.pause();
483
- setIsPaused(true);
484
- } catch (error) {
485
- console.error("Failed to play video:", error);
486
- }
467
+ }
468
+ };
469
+ const videoRefs = useRef<HTMLDivElement>(null); // Create a reference for the element
470
+
471
+ useEffect(() => {
472
+ const observer = new IntersectionObserver(
473
+ (entries) => {
474
+ entries.forEach((entry) => {
475
+ if (entry.isIntersecting === false) {
476
+ if (playerRef?.current?.paused() === false) {
477
+ try {
478
+ playerRef?.current?.pause();
479
+ setIsPaused(true);
480
+ } catch (error) {
481
+ console.error("Failed to play video:", error);
487
482
  }
488
483
  }
489
- });
490
- },
491
- {
492
- threshold: 0.1, // The amount of the component that must be visible (0.1 means 10% visible)
493
- }
494
- );
484
+ }
485
+ });
486
+ },
487
+ {
488
+ threshold: 0.1, // The amount of the component that must be visible (0.1 means 10% visible)
489
+ }
490
+ );
491
+
492
+ if (videoRefs.current) {
493
+ observer.observe(videoRefs.current); // Start observing the component
494
+ }
495
495
 
496
+ return () => {
496
497
  if (videoRefs.current) {
497
- observer.observe(videoRefs.current); // Start observing the component
498
+ observer.unobserve(videoRef.current); // Clean up the observer when the component unmounts
498
499
  }
500
+ };
501
+ }, []);
499
502
 
500
- return () => {
501
- if (videoRefs.current) {
502
- observer.unobserve(videoRef.current); // Clean up the observer when the component unmounts
503
- }
504
- };
505
- }, []);
506
-
507
- const [timeSeeker, setTimeSeeker] = useState<string>("0");
508
- useEffect(() => {
509
- const updateTimeSeeker = () => {
510
- if (playerRef.current && isReady) {
511
- const currentTime = playerRef.current.currentTime();
512
- const duration = playerRef.current.duration();
513
-
514
- if (duration && currentTime !== undefined) {
515
- setTimeSeeker(`${(currentTime / duration) * 100}%`);
516
- } else {
517
- setTimeSeeker("0");
518
- }
503
+ const [timeSeeker, setTimeSeeker] = useState<string>("0");
504
+ useEffect(() => {
505
+ const updateTimeSeeker = () => {
506
+ if (playerRef.current && isReady) {
507
+ const currentTime = playerRef.current.currentTime();
508
+ const duration = playerRef.current.duration();
509
+
510
+ if (duration && currentTime !== undefined) {
511
+ setTimeSeeker(`${(currentTime / duration) * 100}%`);
512
+ } else {
513
+ setTimeSeeker("0");
519
514
  }
520
- };
515
+ }
516
+ };
517
+
518
+ const interval = setInterval(updateTimeSeeker, 500); // Update every 500ms
521
519
 
522
- const interval = setInterval(updateTimeSeeker, 500); // Update every 500ms
520
+ return () => clearInterval(interval); // Cleanup interval on unmount
521
+ }, [playerRef]);
523
522
 
524
- return () => clearInterval(interval); // Cleanup interval on unmount
525
- }, [playerRef]);
523
+ const container = document.getElementById(`video-container-${id}`);
526
524
 
527
- const container = document.getElementById(`video-container-${id}`);
525
+ function handleWidthChange(height: any) {
526
+ setHeightValue(height);
527
+ }
528
528
 
529
- function handleWidthChange(height: any) {
530
- setHeightValue(height);
529
+ const resizeObserver = new ResizeObserver((entries) => {
530
+ for (let entry of entries) {
531
+ const currentHeight = entry.contentRect.height;
532
+ handleWidthChange(currentHeight); // Call the action when width changes
531
533
  }
534
+ });
532
535
 
533
- const resizeObserver = new ResizeObserver((entries) => {
534
- for (let entry of entries) {
535
- const currentHeight = entry.contentRect.height;
536
- handleWidthChange(currentHeight); // Call the action when width changes
536
+ // Start observing the element
537
+ const controlBar = container?.querySelector(".vjs-control-bar");
538
+ if (controlBar) {
539
+ resizeObserver.observe(controlBar);
540
+ }
541
+ function debounce(
542
+ func: (arg: boolean) => void, // The function type should accept a boolean argument
543
+ delay: number
544
+ ) {
545
+ let timeoutId: any;
546
+
547
+ return function (arg: boolean) {
548
+ if (timeoutId) {
549
+ clearTimeout(timeoutId);
537
550
  }
538
- });
539
551
 
540
- // Start observing the element
541
- const controlBar = container?.querySelector(".vjs-control-bar");
542
- if (controlBar) {
543
- resizeObserver.observe(controlBar);
544
- }
545
- function debounce(
546
- func: (arg: boolean) => void, // The function type should accept a boolean argument
547
- delay: number
548
- ) {
549
- let timeoutId: any;
550
-
551
- return function (arg: boolean) {
552
- if (timeoutId) {
553
- clearTimeout(timeoutId);
554
- }
555
-
556
- timeoutId = setTimeout(() => {
557
- func(arg);
558
- }, delay);
559
- };
560
- }
552
+ timeoutId = setTimeout(() => {
553
+ func(arg);
554
+ }, delay);
555
+ };
556
+ }
561
557
 
562
- if (playerRef.current) {
563
- playerRef.current.on("waiting", function () {
564
- debounce((arg) => setIsloading(arg), 300)(true);
565
- });
558
+ if (playerRef.current) {
559
+ playerRef.current.on("waiting", function () {
560
+ debounce((arg) => setIsloading(arg), 300)(true);
561
+ });
566
562
 
567
- playerRef.current.on("playing", function () {
568
- debounce((arg) => setIsloading(arg), 300)(false);
569
- });
570
- }
571
- return (
572
- <>
573
- <Suspense
574
- fallback={
575
- <SvgSkillamiIcon className=" sb-w-16 sb-h-16 sb-animate-spin sb-absolute -sb-top-2 -sb-right-2 "></SvgSkillamiIcon>
576
- }
563
+ playerRef.current.on("playing", function () {
564
+ debounce((arg) => setIsloading(arg), 300)(false);
565
+ });
566
+ }
567
+ return (
568
+ <>
569
+ <Suspense
570
+ fallback={
571
+ <SvgSkillamiIcon className=" sb-w-16 sb-h-16 sb-animate-spin sb-absolute -sb-top-2 -sb-right-2 "></SvgSkillamiIcon>
572
+ }
573
+ >
574
+ <div
575
+ ref={videoRefs}
576
+ id={`video-container-${id}`}
577
+ onMouseMove={() => {
578
+ !isNoteOpen ? handlePlayerClick(event, true) : "";
579
+ }}
580
+ className="sb-relative sb-rounded-md sb-overflow-hidden sb-w-full sb-h-full sb-bottom-2 "
581
+ onMouseEnter={() => setIsHovered(true)}
582
+ onMouseLeave={() => setIsHovered(false)}
577
583
  >
584
+ {bottomRedBar && (
585
+ <div
586
+ ref={childRef}
587
+ onClick={handlePlayerClick}
588
+ className={`sb-h-[3px] sb-transition-opacity sb-duration-500 sb-delay-400 sb-z-10 ease-in-out sb-border-spacing-x-2 sb-absolute sb-bg-[red] sb-bottom-0 ${
589
+ opacity == "100" ? "sb-opacity-0" : "sb-opacity-100"
590
+ }`}
591
+ style={{
592
+ width: timeSeeker,
593
+ }}
594
+ ></div>
595
+ )}
578
596
  <div
579
- ref={videoRefs}
580
- id={`video-container-${id}`}
581
- onMouseMove={() => {
582
- !isNoteOpen ? handlePlayerClick(event, true) : "";
583
- }}
584
- className="sb-relative sb-rounded-md sb-overflow-hidden sb-w-full sb-h-full sb-bottom-2 "
585
- onMouseEnter={() => setIsHovered(true)}
586
- onMouseLeave={() => setIsHovered(false)}
597
+ className="hover:sb-cursor-pointer sb-w-full sb-h-full"
598
+ // Attach click event
599
+ data-vjs-player
587
600
  >
588
- {bottomRedBar && (
589
- <div
590
- ref={childRef}
591
- onClick={handlePlayerClick}
592
- className={`sb-h-[3px] sb-transition-opacity sb-duration-500 sb-delay-400 sb-z-10 ease-in-out sb-border-spacing-x-2 sb-absolute sb-bg-[red] sb-bottom-0 ${
593
- opacity == "100" ? "sb-opacity-0" : "sb-opacity-100"
594
- }`}
595
- style={{
596
- width: timeSeeker,
597
- }}
598
- ></div>
599
- )}
600
601
  <div
601
- className="hover:sb-cursor-pointer sb-w-full sb-h-full"
602
- // Attach click event
603
- data-vjs-player
604
- >
605
- <div
606
- onClick={handlePlayerClick}
607
- ref={videoRef}
608
- className="sb-h-full sb-w-full sb-relative"
609
- ></div>
610
- </div>
602
+ onClick={handlePlayerClick}
603
+ ref={videoRef}
604
+ className="sb-h-full sb-w-full sb-relative"
605
+ ></div>
611
606
  </div>
612
- </Suspense>
613
- </>
614
- );
615
- }
616
- );
607
+ </div>
608
+ </Suspense>
609
+ </>
610
+ );
611
+ };
612
+
617
613
  export default VideoPlayerComponent;