@nikelroot/video-player 0.2.8 → 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 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.currentSrc || !!video.getAttribute("src");
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
- const attachedNativeMedia = ensureNativeMediaAttached();
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.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.currentSrc || !!video.getAttribute("src");
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
- const attachedNativeMedia = ensureNativeMediaAttached();
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]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nikelroot/video-player",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Standalone React video player with HLS support.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",