@nikelroot/video-player 0.1.2 → 0.1.4
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/README.md +4 -0
- package/dist/index.cjs +12 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,11 +17,15 @@ npm install react react-dom styled-components
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```tsx
|
|
20
|
+
import { useRef } from 'react';
|
|
20
21
|
import VideoPlayer from '@nikelroot/video-player';
|
|
21
22
|
|
|
22
23
|
export function Example() {
|
|
24
|
+
const videoRef = useRef<HTMLVideoElement | null>(null);
|
|
25
|
+
|
|
23
26
|
return (
|
|
24
27
|
<VideoPlayer
|
|
28
|
+
videoRef={videoRef}
|
|
25
29
|
videoSrc="https://example.com/stream.m3u8"
|
|
26
30
|
controlsVariant="full"
|
|
27
31
|
live={false}
|
package/dist/index.cjs
CHANGED
|
@@ -740,6 +740,14 @@ var isLikelyHlsSource = (src) => {
|
|
|
740
740
|
return /\.m3u8($|[?#])/i.test(src);
|
|
741
741
|
}
|
|
742
742
|
};
|
|
743
|
+
var assignRef = (ref, value) => {
|
|
744
|
+
if (!ref) return;
|
|
745
|
+
if (typeof ref === "function") {
|
|
746
|
+
ref(value);
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
ref.current = value;
|
|
750
|
+
};
|
|
743
751
|
var VideoPlayerBase = (props, ref) => {
|
|
744
752
|
const {
|
|
745
753
|
controlsVariant = "none",
|
|
@@ -760,6 +768,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
760
768
|
alwaysShowSegments = false,
|
|
761
769
|
initialTime = 0,
|
|
762
770
|
reloadKey,
|
|
771
|
+
videoRef: externalVideoRef,
|
|
763
772
|
onVideoRefChange,
|
|
764
773
|
handleClick = true,
|
|
765
774
|
onPointerDown,
|
|
@@ -901,6 +910,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
901
910
|
prev.removeEventListener("durationchange", onDur);
|
|
902
911
|
}
|
|
903
912
|
videoRef.current = el;
|
|
913
|
+
assignRef(externalVideoRef, el);
|
|
904
914
|
onVideoRefChange == null ? void 0 : onVideoRefChange(el);
|
|
905
915
|
notifyActiveChange(el, "ref");
|
|
906
916
|
if (!el) return;
|
|
@@ -908,7 +918,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
908
918
|
el.addEventListener("timeupdate", onTime);
|
|
909
919
|
el.addEventListener("durationchange", onDur);
|
|
910
920
|
},
|
|
911
|
-
[muted, notifyActiveChange, onDur, onTime, onVideoRefChange]
|
|
921
|
+
[externalVideoRef, muted, notifyActiveChange, onDur, onTime, onVideoRefChange]
|
|
912
922
|
);
|
|
913
923
|
const pauseOtherVideos = (0, import_react2.useCallback)(
|
|
914
924
|
(el) => {
|
|
@@ -1400,6 +1410,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1400
1410
|
"video",
|
|
1401
1411
|
{
|
|
1402
1412
|
...videoProps,
|
|
1413
|
+
controls: false,
|
|
1403
1414
|
ref: setVideoEl,
|
|
1404
1415
|
crossOrigin,
|
|
1405
1416
|
playsInline: true,
|
package/dist/index.d.cts
CHANGED
|
@@ -36,7 +36,7 @@ interface VideoPlayerProps extends Omit<React.VideoHTMLAttributes<HTMLVideoEleme
|
|
|
36
36
|
videoSrc: string;
|
|
37
37
|
sourceType?: 'auto' | 'hls' | 'native';
|
|
38
38
|
type?: string;
|
|
39
|
-
controlsVariant
|
|
39
|
+
controlsVariant: ControlsVariant;
|
|
40
40
|
autoPlay?: boolean;
|
|
41
41
|
preload?: '' | 'none' | 'auto' | 'metadata';
|
|
42
42
|
loop?: boolean;
|
|
@@ -61,6 +61,7 @@ interface VideoPlayerProps extends Omit<React.VideoHTMLAttributes<HTMLVideoEleme
|
|
|
61
61
|
duration?: number;
|
|
62
62
|
onTimeChange?: (time: number, video: HTMLVideoElement) => void;
|
|
63
63
|
onDurationChange?: (duration: number, video: HTMLVideoElement) => void;
|
|
64
|
+
videoRef?: React.Ref<HTMLVideoElement>;
|
|
64
65
|
onVideoRefChange?: (video: HTMLVideoElement | null) => void;
|
|
65
66
|
onActiveChange?: (payload: VideoPlayerActiveChangePayload) => void;
|
|
66
67
|
onPlaybackError?: (payload: VideoPlayerPlaybackError) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ interface VideoPlayerProps extends Omit<React.VideoHTMLAttributes<HTMLVideoEleme
|
|
|
36
36
|
videoSrc: string;
|
|
37
37
|
sourceType?: 'auto' | 'hls' | 'native';
|
|
38
38
|
type?: string;
|
|
39
|
-
controlsVariant
|
|
39
|
+
controlsVariant: ControlsVariant;
|
|
40
40
|
autoPlay?: boolean;
|
|
41
41
|
preload?: '' | 'none' | 'auto' | 'metadata';
|
|
42
42
|
loop?: boolean;
|
|
@@ -61,6 +61,7 @@ interface VideoPlayerProps extends Omit<React.VideoHTMLAttributes<HTMLVideoEleme
|
|
|
61
61
|
duration?: number;
|
|
62
62
|
onTimeChange?: (time: number, video: HTMLVideoElement) => void;
|
|
63
63
|
onDurationChange?: (duration: number, video: HTMLVideoElement) => void;
|
|
64
|
+
videoRef?: React.Ref<HTMLVideoElement>;
|
|
64
65
|
onVideoRefChange?: (video: HTMLVideoElement | null) => void;
|
|
65
66
|
onActiveChange?: (payload: VideoPlayerActiveChangePayload) => void;
|
|
66
67
|
onPlaybackError?: (payload: VideoPlayerPlaybackError) => void;
|
package/dist/index.js
CHANGED
|
@@ -711,6 +711,14 @@ var isLikelyHlsSource = (src) => {
|
|
|
711
711
|
return /\.m3u8($|[?#])/i.test(src);
|
|
712
712
|
}
|
|
713
713
|
};
|
|
714
|
+
var assignRef = (ref, value) => {
|
|
715
|
+
if (!ref) return;
|
|
716
|
+
if (typeof ref === "function") {
|
|
717
|
+
ref(value);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
ref.current = value;
|
|
721
|
+
};
|
|
714
722
|
var VideoPlayerBase = (props, ref) => {
|
|
715
723
|
const {
|
|
716
724
|
controlsVariant = "none",
|
|
@@ -731,6 +739,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
731
739
|
alwaysShowSegments = false,
|
|
732
740
|
initialTime = 0,
|
|
733
741
|
reloadKey,
|
|
742
|
+
videoRef: externalVideoRef,
|
|
734
743
|
onVideoRefChange,
|
|
735
744
|
handleClick = true,
|
|
736
745
|
onPointerDown,
|
|
@@ -872,6 +881,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
872
881
|
prev.removeEventListener("durationchange", onDur);
|
|
873
882
|
}
|
|
874
883
|
videoRef.current = el;
|
|
884
|
+
assignRef(externalVideoRef, el);
|
|
875
885
|
onVideoRefChange == null ? void 0 : onVideoRefChange(el);
|
|
876
886
|
notifyActiveChange(el, "ref");
|
|
877
887
|
if (!el) return;
|
|
@@ -879,7 +889,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
879
889
|
el.addEventListener("timeupdate", onTime);
|
|
880
890
|
el.addEventListener("durationchange", onDur);
|
|
881
891
|
},
|
|
882
|
-
[muted, notifyActiveChange, onDur, onTime, onVideoRefChange]
|
|
892
|
+
[externalVideoRef, muted, notifyActiveChange, onDur, onTime, onVideoRefChange]
|
|
883
893
|
);
|
|
884
894
|
const pauseOtherVideos = useCallback(
|
|
885
895
|
(el) => {
|
|
@@ -1371,6 +1381,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1371
1381
|
"video",
|
|
1372
1382
|
{
|
|
1373
1383
|
...videoProps,
|
|
1384
|
+
controls: false,
|
|
1374
1385
|
ref: setVideoEl,
|
|
1375
1386
|
crossOrigin,
|
|
1376
1387
|
playsInline: true,
|