@nikelroot/video-player 0.1.8 → 0.1.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/dist/index.cjs +26 -6
- package/dist/index.js +26 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -864,9 +864,13 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
864
864
|
const [reloadToken, setReloadToken] = (0, import_react3.useState)(0);
|
|
865
865
|
const playing = playingProp != null ? playingProp : playingState;
|
|
866
866
|
const muted = mutedProp != null ? mutedProp : mutedState;
|
|
867
|
+
const isDurationControlled = durationProp !== void 0;
|
|
868
|
+
const isCurrentTimeControlled = currentTimeProp !== void 0;
|
|
867
869
|
const duration = durationProp != null ? durationProp : durationState;
|
|
868
870
|
const currentTime = currentTimeProp != null ? currentTimeProp : currentTimeState;
|
|
869
871
|
const fullscreenAllowed = active != null ? active : true;
|
|
872
|
+
const onTimeChangeRef = (0, import_react3.useRef)(onTimeChange);
|
|
873
|
+
const onDurationChangeRef = (0, import_react3.useRef)(onDurationChange);
|
|
870
874
|
const setTimeD = (0, import_react3.useRef)(
|
|
871
875
|
createThrottledNumberFn((value) => {
|
|
872
876
|
const v = videoRef.current;
|
|
@@ -930,20 +934,28 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
930
934
|
},
|
|
931
935
|
[onActiveChange]
|
|
932
936
|
);
|
|
937
|
+
(0, import_react3.useEffect)(() => {
|
|
938
|
+
onTimeChangeRef.current = onTimeChange;
|
|
939
|
+
}, [onTimeChange]);
|
|
940
|
+
(0, import_react3.useEffect)(() => {
|
|
941
|
+
onDurationChangeRef.current = onDurationChange;
|
|
942
|
+
}, [onDurationChange]);
|
|
933
943
|
const onTime = (0, import_react3.useCallback)(() => {
|
|
944
|
+
var _a;
|
|
934
945
|
const el = videoRef.current;
|
|
935
946
|
if (!el) return;
|
|
936
947
|
const nextTime = Number.isFinite(el.currentTime) ? el.currentTime : 0;
|
|
937
|
-
if (
|
|
938
|
-
|
|
939
|
-
}, [
|
|
948
|
+
if (!isCurrentTimeControlled) setCurrentTimeState(nextTime);
|
|
949
|
+
(_a = onTimeChangeRef.current) == null ? void 0 : _a.call(onTimeChangeRef, nextTime, el);
|
|
950
|
+
}, [isCurrentTimeControlled]);
|
|
940
951
|
const onDur = (0, import_react3.useCallback)(() => {
|
|
952
|
+
var _a;
|
|
941
953
|
const el = videoRef.current;
|
|
942
954
|
if (!el) return;
|
|
943
955
|
const nextDuration = Number.isFinite(el.duration) ? el.duration : 0;
|
|
944
|
-
if (
|
|
945
|
-
|
|
946
|
-
}, [
|
|
956
|
+
if (!isDurationControlled) setDurationState(nextDuration);
|
|
957
|
+
(_a = onDurationChangeRef.current) == null ? void 0 : _a.call(onDurationChangeRef, nextDuration, el);
|
|
958
|
+
}, [isDurationControlled]);
|
|
947
959
|
const setVideoEl = (0, import_react3.useCallback)(
|
|
948
960
|
(el) => {
|
|
949
961
|
const prev = videoRef.current;
|
|
@@ -1438,6 +1450,14 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1438
1450
|
destroy();
|
|
1439
1451
|
};
|
|
1440
1452
|
}, [destroy]);
|
|
1453
|
+
const lastActiveState = (0, import_react3.useRef)(active);
|
|
1454
|
+
(0, import_react3.useEffect)(() => {
|
|
1455
|
+
const prevActive = lastActiveState.current;
|
|
1456
|
+
lastActiveState.current = active;
|
|
1457
|
+
if (active === true && prevActive !== true) {
|
|
1458
|
+
void playAction();
|
|
1459
|
+
}
|
|
1460
|
+
}, [active, playAction]);
|
|
1441
1461
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1442
1462
|
VideoPlayerStyles,
|
|
1443
1463
|
{
|
package/dist/index.js
CHANGED
|
@@ -835,9 +835,13 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
835
835
|
const [reloadToken, setReloadToken] = useState(0);
|
|
836
836
|
const playing = playingProp != null ? playingProp : playingState;
|
|
837
837
|
const muted = mutedProp != null ? mutedProp : mutedState;
|
|
838
|
+
const isDurationControlled = durationProp !== void 0;
|
|
839
|
+
const isCurrentTimeControlled = currentTimeProp !== void 0;
|
|
838
840
|
const duration = durationProp != null ? durationProp : durationState;
|
|
839
841
|
const currentTime = currentTimeProp != null ? currentTimeProp : currentTimeState;
|
|
840
842
|
const fullscreenAllowed = active != null ? active : true;
|
|
843
|
+
const onTimeChangeRef = useRef2(onTimeChange);
|
|
844
|
+
const onDurationChangeRef = useRef2(onDurationChange);
|
|
841
845
|
const setTimeD = useRef2(
|
|
842
846
|
createThrottledNumberFn((value) => {
|
|
843
847
|
const v = videoRef.current;
|
|
@@ -901,20 +905,28 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
901
905
|
},
|
|
902
906
|
[onActiveChange]
|
|
903
907
|
);
|
|
908
|
+
useEffect(() => {
|
|
909
|
+
onTimeChangeRef.current = onTimeChange;
|
|
910
|
+
}, [onTimeChange]);
|
|
911
|
+
useEffect(() => {
|
|
912
|
+
onDurationChangeRef.current = onDurationChange;
|
|
913
|
+
}, [onDurationChange]);
|
|
904
914
|
const onTime = useCallback(() => {
|
|
915
|
+
var _a;
|
|
905
916
|
const el = videoRef.current;
|
|
906
917
|
if (!el) return;
|
|
907
918
|
const nextTime = Number.isFinite(el.currentTime) ? el.currentTime : 0;
|
|
908
|
-
if (
|
|
909
|
-
|
|
910
|
-
}, [
|
|
919
|
+
if (!isCurrentTimeControlled) setCurrentTimeState(nextTime);
|
|
920
|
+
(_a = onTimeChangeRef.current) == null ? void 0 : _a.call(onTimeChangeRef, nextTime, el);
|
|
921
|
+
}, [isCurrentTimeControlled]);
|
|
911
922
|
const onDur = useCallback(() => {
|
|
923
|
+
var _a;
|
|
912
924
|
const el = videoRef.current;
|
|
913
925
|
if (!el) return;
|
|
914
926
|
const nextDuration = Number.isFinite(el.duration) ? el.duration : 0;
|
|
915
|
-
if (
|
|
916
|
-
|
|
917
|
-
}, [
|
|
927
|
+
if (!isDurationControlled) setDurationState(nextDuration);
|
|
928
|
+
(_a = onDurationChangeRef.current) == null ? void 0 : _a.call(onDurationChangeRef, nextDuration, el);
|
|
929
|
+
}, [isDurationControlled]);
|
|
918
930
|
const setVideoEl = useCallback(
|
|
919
931
|
(el) => {
|
|
920
932
|
const prev = videoRef.current;
|
|
@@ -1409,6 +1421,14 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1409
1421
|
destroy();
|
|
1410
1422
|
};
|
|
1411
1423
|
}, [destroy]);
|
|
1424
|
+
const lastActiveState = useRef2(active);
|
|
1425
|
+
useEffect(() => {
|
|
1426
|
+
const prevActive = lastActiveState.current;
|
|
1427
|
+
lastActiveState.current = active;
|
|
1428
|
+
if (active === true && prevActive !== true) {
|
|
1429
|
+
void playAction();
|
|
1430
|
+
}
|
|
1431
|
+
}, [active, playAction]);
|
|
1412
1432
|
return /* @__PURE__ */ jsxs2(
|
|
1413
1433
|
VideoPlayerStyles,
|
|
1414
1434
|
{
|