@nikelroot/video-player 0.2.7 → 0.2.9
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/dist/index.cjs +10 -4
- package/dist/index.js +10 -4
- package/package.json +1 -1
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);
|
|
@@ -930,9 +931,11 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
930
931
|
}, []);
|
|
931
932
|
const ensureNativeMediaAttached = (0, import_react3.useCallback)(() => {
|
|
932
933
|
const video = videoRef.current;
|
|
933
|
-
if (!video || sourceLoadMode.current !== "native" || isVideoSourceAttached(video)) return;
|
|
934
|
+
if (!video || sourceLoadMode.current !== "native" || isVideoSourceAttached(video)) return false;
|
|
934
935
|
video.src = videoSrc;
|
|
935
936
|
if (initialTime > 0) video.currentTime = initialTime;
|
|
937
|
+
video.load();
|
|
938
|
+
return true;
|
|
936
939
|
}, [initialTime, videoSrc]);
|
|
937
940
|
const setNextPlaying = (0, import_react3.useCallback)(
|
|
938
941
|
(value) => {
|
|
@@ -1035,8 +1038,8 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1035
1038
|
pendingPlay.current = true;
|
|
1036
1039
|
pauseOtherVideos(el);
|
|
1037
1040
|
ensureNativeMediaAttached();
|
|
1038
|
-
if (sourceLoadMode.current === "native" && !canAttemptPlayback(el)) return;
|
|
1039
1041
|
try {
|
|
1042
|
+
playRequestInFlight.current = true;
|
|
1040
1043
|
await el.play();
|
|
1041
1044
|
pendingPlay.current = false;
|
|
1042
1045
|
clearErrorState();
|
|
@@ -1050,6 +1053,8 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1050
1053
|
pendingPlay.current = false;
|
|
1051
1054
|
console.debug(e);
|
|
1052
1055
|
reportError(e, { type: "play" }, messages.playFailed);
|
|
1056
|
+
} finally {
|
|
1057
|
+
playRequestInFlight.current = false;
|
|
1053
1058
|
}
|
|
1054
1059
|
if (scrollTo === true) {
|
|
1055
1060
|
const rect = el.getBoundingClientRect();
|
|
@@ -1409,6 +1414,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1409
1414
|
}, [messages, reportError, videoSrc]);
|
|
1410
1415
|
const videoLoadedHandler = (0, import_react3.useCallback)(() => {
|
|
1411
1416
|
clearErrorState();
|
|
1417
|
+
if (playRequestInFlight.current) return;
|
|
1412
1418
|
if (!pendingPlay.current || active === false || !canAttemptPlayback(videoRef.current)) return;
|
|
1413
1419
|
void playAction();
|
|
1414
1420
|
}, [active, clearErrorState, playAction]);
|
|
@@ -1441,7 +1447,6 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1441
1447
|
}, [muted]);
|
|
1442
1448
|
(0, import_react3.useEffect)(() => {
|
|
1443
1449
|
if (playingProp === void 0) return;
|
|
1444
|
-
if (!canAttemptPlayback(videoRef.current)) return;
|
|
1445
1450
|
if (playingProp) void playAction();
|
|
1446
1451
|
else pauseAction();
|
|
1447
1452
|
}, [pauseAction, playAction, playingProp]);
|
|
@@ -1586,6 +1591,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1586
1591
|
onPlay: () => setNextPlaying(true),
|
|
1587
1592
|
onPause: () => setNextPlaying(false),
|
|
1588
1593
|
onEnded: () => setNextPlaying(false),
|
|
1594
|
+
onLoadedMetadata: videoLoadedHandler,
|
|
1589
1595
|
onLoadedData: videoLoadedHandler,
|
|
1590
1596
|
onCanPlay: videoLoadedHandler,
|
|
1591
1597
|
onError: videoErrorHandler,
|
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);
|
|
@@ -901,9 +902,11 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
901
902
|
}, []);
|
|
902
903
|
const ensureNativeMediaAttached = useCallback(() => {
|
|
903
904
|
const video = videoRef.current;
|
|
904
|
-
if (!video || sourceLoadMode.current !== "native" || isVideoSourceAttached(video)) return;
|
|
905
|
+
if (!video || sourceLoadMode.current !== "native" || isVideoSourceAttached(video)) return false;
|
|
905
906
|
video.src = videoSrc;
|
|
906
907
|
if (initialTime > 0) video.currentTime = initialTime;
|
|
908
|
+
video.load();
|
|
909
|
+
return true;
|
|
907
910
|
}, [initialTime, videoSrc]);
|
|
908
911
|
const setNextPlaying = useCallback(
|
|
909
912
|
(value) => {
|
|
@@ -1006,8 +1009,8 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1006
1009
|
pendingPlay.current = true;
|
|
1007
1010
|
pauseOtherVideos(el);
|
|
1008
1011
|
ensureNativeMediaAttached();
|
|
1009
|
-
if (sourceLoadMode.current === "native" && !canAttemptPlayback(el)) return;
|
|
1010
1012
|
try {
|
|
1013
|
+
playRequestInFlight.current = true;
|
|
1011
1014
|
await el.play();
|
|
1012
1015
|
pendingPlay.current = false;
|
|
1013
1016
|
clearErrorState();
|
|
@@ -1021,6 +1024,8 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1021
1024
|
pendingPlay.current = false;
|
|
1022
1025
|
console.debug(e);
|
|
1023
1026
|
reportError(e, { type: "play" }, messages.playFailed);
|
|
1027
|
+
} finally {
|
|
1028
|
+
playRequestInFlight.current = false;
|
|
1024
1029
|
}
|
|
1025
1030
|
if (scrollTo === true) {
|
|
1026
1031
|
const rect = el.getBoundingClientRect();
|
|
@@ -1380,6 +1385,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1380
1385
|
}, [messages, reportError, videoSrc]);
|
|
1381
1386
|
const videoLoadedHandler = useCallback(() => {
|
|
1382
1387
|
clearErrorState();
|
|
1388
|
+
if (playRequestInFlight.current) return;
|
|
1383
1389
|
if (!pendingPlay.current || active === false || !canAttemptPlayback(videoRef.current)) return;
|
|
1384
1390
|
void playAction();
|
|
1385
1391
|
}, [active, clearErrorState, playAction]);
|
|
@@ -1412,7 +1418,6 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1412
1418
|
}, [muted]);
|
|
1413
1419
|
useEffect(() => {
|
|
1414
1420
|
if (playingProp === void 0) return;
|
|
1415
|
-
if (!canAttemptPlayback(videoRef.current)) return;
|
|
1416
1421
|
if (playingProp) void playAction();
|
|
1417
1422
|
else pauseAction();
|
|
1418
1423
|
}, [pauseAction, playAction, playingProp]);
|
|
@@ -1557,6 +1562,7 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1557
1562
|
onPlay: () => setNextPlaying(true),
|
|
1558
1563
|
onPause: () => setNextPlaying(false),
|
|
1559
1564
|
onEnded: () => setNextPlaying(false),
|
|
1565
|
+
onLoadedMetadata: videoLoadedHandler,
|
|
1560
1566
|
onLoadedData: videoLoadedHandler,
|
|
1561
1567
|
onCanPlay: videoLoadedHandler,
|
|
1562
1568
|
onError: videoErrorHandler,
|