@nikelroot/video-player 0.2.8 → 0.2.10
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 +3 -2
- package/dist/index.cjs +7 -6
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,9 +25,8 @@ export function Example() {
|
|
|
25
25
|
|
|
26
26
|
return (
|
|
27
27
|
<VideoPlayer
|
|
28
|
-
videoRef={videoRef}
|
|
29
28
|
videoSrc="https://example.com/stream.m3u8"
|
|
30
|
-
|
|
29
|
+
videoRef={videoRef}
|
|
31
30
|
active={true}
|
|
32
31
|
live={false}
|
|
33
32
|
autoPlay={false}
|
|
@@ -37,6 +36,8 @@ export function Example() {
|
|
|
37
36
|
}
|
|
38
37
|
```
|
|
39
38
|
|
|
39
|
+
Only `videoSrc` is required. `controlsVariant` defaults to `"none"`; set it to `"full"`, `"fullscreen-only"`, or `"tiny"` to render built-in controls.
|
|
40
|
+
|
|
40
41
|
When `active` is `true`, pressing `F` toggles fullscreen.
|
|
41
42
|
|
|
42
43
|
## Multiple MP4 players
|
package/dist/index.cjs
CHANGED
|
@@ -740,7 +740,7 @@ var canAttemptPlayback = (video) => {
|
|
|
740
740
|
return !!video && video.readyState >= HTMLMediaElement.HAVE_METADATA;
|
|
741
741
|
};
|
|
742
742
|
var isVideoSourceAttached = (video) => {
|
|
743
|
-
return !!video.
|
|
743
|
+
return !!video.getAttribute("src");
|
|
744
744
|
};
|
|
745
745
|
function hasNativeHlsSupport() {
|
|
746
746
|
if (typeof navigator === "undefined" || typeof document === "undefined") return false;
|
|
@@ -863,6 +863,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
863
863
|
const sourceLoadId = (0, import_react3.useRef)(0);
|
|
864
864
|
const sourceLoadMode = (0, import_react3.useRef)("native");
|
|
865
865
|
const pendingPlay = (0, import_react3.useRef)(false);
|
|
866
|
+
const playRequestInFlight = (0, import_react3.useRef)(false);
|
|
866
867
|
const [playingState, setPlayingState] = (0, import_react3.useState)(!!defaultPlaying);
|
|
867
868
|
const [mutedState, setMutedState] = (0, import_react3.useState)(!!defaultMuted);
|
|
868
869
|
const [durationState, setDurationState] = (0, import_react3.useState)(0);
|
|
@@ -1036,12 +1037,9 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1036
1037
|
if (!el) return;
|
|
1037
1038
|
pendingPlay.current = true;
|
|
1038
1039
|
pauseOtherVideos(el);
|
|
1039
|
-
|
|
1040
|
-
if (sourceLoadMode.current === "native" && !canAttemptPlayback(el)) {
|
|
1041
|
-
if (attachedNativeMedia) clearErrorState();
|
|
1042
|
-
return;
|
|
1043
|
-
}
|
|
1040
|
+
ensureNativeMediaAttached();
|
|
1044
1041
|
try {
|
|
1042
|
+
playRequestInFlight.current = true;
|
|
1045
1043
|
await el.play();
|
|
1046
1044
|
pendingPlay.current = false;
|
|
1047
1045
|
clearErrorState();
|
|
@@ -1055,6 +1053,8 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1055
1053
|
pendingPlay.current = false;
|
|
1056
1054
|
console.debug(e);
|
|
1057
1055
|
reportError(e, { type: "play" }, messages.playFailed);
|
|
1056
|
+
} finally {
|
|
1057
|
+
playRequestInFlight.current = false;
|
|
1058
1058
|
}
|
|
1059
1059
|
if (scrollTo === true) {
|
|
1060
1060
|
const rect = el.getBoundingClientRect();
|
|
@@ -1414,6 +1414,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1414
1414
|
}, [messages, reportError, videoSrc]);
|
|
1415
1415
|
const videoLoadedHandler = (0, import_react3.useCallback)(() => {
|
|
1416
1416
|
clearErrorState();
|
|
1417
|
+
if (playRequestInFlight.current) return;
|
|
1417
1418
|
if (!pendingPlay.current || active === false || !canAttemptPlayback(videoRef.current)) return;
|
|
1418
1419
|
void playAction();
|
|
1419
1420
|
}, [active, clearErrorState, playAction]);
|
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
|
active?: boolean;
|
|
41
41
|
autoPlay?: boolean;
|
|
42
42
|
preload?: '' | 'none' | 'auto' | 'metadata';
|
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
|
active?: boolean;
|
|
41
41
|
autoPlay?: boolean;
|
|
42
42
|
preload?: '' | 'none' | 'auto' | 'metadata';
|
package/dist/index.js
CHANGED
|
@@ -711,7 +711,7 @@ var canAttemptPlayback = (video) => {
|
|
|
711
711
|
return !!video && video.readyState >= HTMLMediaElement.HAVE_METADATA;
|
|
712
712
|
};
|
|
713
713
|
var isVideoSourceAttached = (video) => {
|
|
714
|
-
return !!video.
|
|
714
|
+
return !!video.getAttribute("src");
|
|
715
715
|
};
|
|
716
716
|
function hasNativeHlsSupport() {
|
|
717
717
|
if (typeof navigator === "undefined" || typeof document === "undefined") return false;
|
|
@@ -834,6 +834,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
834
834
|
const sourceLoadId = useRef2(0);
|
|
835
835
|
const sourceLoadMode = useRef2("native");
|
|
836
836
|
const pendingPlay = useRef2(false);
|
|
837
|
+
const playRequestInFlight = useRef2(false);
|
|
837
838
|
const [playingState, setPlayingState] = useState(!!defaultPlaying);
|
|
838
839
|
const [mutedState, setMutedState] = useState(!!defaultMuted);
|
|
839
840
|
const [durationState, setDurationState] = useState(0);
|
|
@@ -1007,12 +1008,9 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1007
1008
|
if (!el) return;
|
|
1008
1009
|
pendingPlay.current = true;
|
|
1009
1010
|
pauseOtherVideos(el);
|
|
1010
|
-
|
|
1011
|
-
if (sourceLoadMode.current === "native" && !canAttemptPlayback(el)) {
|
|
1012
|
-
if (attachedNativeMedia) clearErrorState();
|
|
1013
|
-
return;
|
|
1014
|
-
}
|
|
1011
|
+
ensureNativeMediaAttached();
|
|
1015
1012
|
try {
|
|
1013
|
+
playRequestInFlight.current = true;
|
|
1016
1014
|
await el.play();
|
|
1017
1015
|
pendingPlay.current = false;
|
|
1018
1016
|
clearErrorState();
|
|
@@ -1026,6 +1024,8 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1026
1024
|
pendingPlay.current = false;
|
|
1027
1025
|
console.debug(e);
|
|
1028
1026
|
reportError(e, { type: "play" }, messages.playFailed);
|
|
1027
|
+
} finally {
|
|
1028
|
+
playRequestInFlight.current = false;
|
|
1029
1029
|
}
|
|
1030
1030
|
if (scrollTo === true) {
|
|
1031
1031
|
const rect = el.getBoundingClientRect();
|
|
@@ -1385,6 +1385,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1385
1385
|
}, [messages, reportError, videoSrc]);
|
|
1386
1386
|
const videoLoadedHandler = useCallback(() => {
|
|
1387
1387
|
clearErrorState();
|
|
1388
|
+
if (playRequestInFlight.current) return;
|
|
1388
1389
|
if (!pendingPlay.current || active === false || !canAttemptPlayback(videoRef.current)) return;
|
|
1389
1390
|
void playAction();
|
|
1390
1391
|
}, [active, clearErrorState, playAction]);
|