@nikelroot/video-player 0.1.9 → 0.1.11
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 +19 -10
- package/dist/index.js +19 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -864,9 +864,15 @@ 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);
|
|
874
|
+
onTimeChangeRef.current = onTimeChange;
|
|
875
|
+
onDurationChangeRef.current = onDurationChange;
|
|
870
876
|
const setTimeD = (0, import_react3.useRef)(
|
|
871
877
|
createThrottledNumberFn((value) => {
|
|
872
878
|
const v = videoRef.current;
|
|
@@ -931,19 +937,21 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
931
937
|
[onActiveChange]
|
|
932
938
|
);
|
|
933
939
|
const onTime = (0, import_react3.useCallback)(() => {
|
|
940
|
+
var _a;
|
|
934
941
|
const el = videoRef.current;
|
|
935
942
|
if (!el) return;
|
|
936
943
|
const nextTime = Number.isFinite(el.currentTime) ? el.currentTime : 0;
|
|
937
|
-
if (
|
|
938
|
-
|
|
939
|
-
}, [
|
|
944
|
+
if (!isCurrentTimeControlled) setCurrentTimeState(nextTime);
|
|
945
|
+
(_a = onTimeChangeRef.current) == null ? void 0 : _a.call(onTimeChangeRef, nextTime, el);
|
|
946
|
+
}, [isCurrentTimeControlled]);
|
|
940
947
|
const onDur = (0, import_react3.useCallback)(() => {
|
|
948
|
+
var _a;
|
|
941
949
|
const el = videoRef.current;
|
|
942
950
|
if (!el) return;
|
|
943
951
|
const nextDuration = Number.isFinite(el.duration) ? el.duration : 0;
|
|
944
|
-
if (
|
|
945
|
-
|
|
946
|
-
}, [
|
|
952
|
+
if (!isDurationControlled) setDurationState(nextDuration);
|
|
953
|
+
(_a = onDurationChangeRef.current) == null ? void 0 : _a.call(onDurationChangeRef, nextDuration, el);
|
|
954
|
+
}, [isDurationControlled]);
|
|
947
955
|
const setVideoEl = (0, import_react3.useCallback)(
|
|
948
956
|
(el) => {
|
|
949
957
|
const prev = videoRef.current;
|
|
@@ -1440,11 +1448,12 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1440
1448
|
}, [destroy]);
|
|
1441
1449
|
const lastActiveState = (0, import_react3.useRef)(active);
|
|
1442
1450
|
(0, import_react3.useEffect)(() => {
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1451
|
+
const prevActive = lastActiveState.current;
|
|
1452
|
+
lastActiveState.current = active;
|
|
1453
|
+
if (active === true && prevActive !== true) {
|
|
1454
|
+
void playAction();
|
|
1446
1455
|
}
|
|
1447
|
-
}, [active]);
|
|
1456
|
+
}, [active, playAction]);
|
|
1448
1457
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1449
1458
|
VideoPlayerStyles,
|
|
1450
1459
|
{
|
package/dist/index.js
CHANGED
|
@@ -835,9 +835,15 @@ 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);
|
|
845
|
+
onTimeChangeRef.current = onTimeChange;
|
|
846
|
+
onDurationChangeRef.current = onDurationChange;
|
|
841
847
|
const setTimeD = useRef2(
|
|
842
848
|
createThrottledNumberFn((value) => {
|
|
843
849
|
const v = videoRef.current;
|
|
@@ -902,19 +908,21 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
902
908
|
[onActiveChange]
|
|
903
909
|
);
|
|
904
910
|
const onTime = useCallback(() => {
|
|
911
|
+
var _a;
|
|
905
912
|
const el = videoRef.current;
|
|
906
913
|
if (!el) return;
|
|
907
914
|
const nextTime = Number.isFinite(el.currentTime) ? el.currentTime : 0;
|
|
908
|
-
if (
|
|
909
|
-
|
|
910
|
-
}, [
|
|
915
|
+
if (!isCurrentTimeControlled) setCurrentTimeState(nextTime);
|
|
916
|
+
(_a = onTimeChangeRef.current) == null ? void 0 : _a.call(onTimeChangeRef, nextTime, el);
|
|
917
|
+
}, [isCurrentTimeControlled]);
|
|
911
918
|
const onDur = useCallback(() => {
|
|
919
|
+
var _a;
|
|
912
920
|
const el = videoRef.current;
|
|
913
921
|
if (!el) return;
|
|
914
922
|
const nextDuration = Number.isFinite(el.duration) ? el.duration : 0;
|
|
915
|
-
if (
|
|
916
|
-
|
|
917
|
-
}, [
|
|
923
|
+
if (!isDurationControlled) setDurationState(nextDuration);
|
|
924
|
+
(_a = onDurationChangeRef.current) == null ? void 0 : _a.call(onDurationChangeRef, nextDuration, el);
|
|
925
|
+
}, [isDurationControlled]);
|
|
918
926
|
const setVideoEl = useCallback(
|
|
919
927
|
(el) => {
|
|
920
928
|
const prev = videoRef.current;
|
|
@@ -1411,11 +1419,12 @@ var VideoPlayerBase = (props, ref) => {
|
|
|
1411
1419
|
}, [destroy]);
|
|
1412
1420
|
const lastActiveState = useRef2(active);
|
|
1413
1421
|
useEffect(() => {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1422
|
+
const prevActive = lastActiveState.current;
|
|
1423
|
+
lastActiveState.current = active;
|
|
1424
|
+
if (active === true && prevActive !== true) {
|
|
1425
|
+
void playAction();
|
|
1417
1426
|
}
|
|
1418
|
-
}, [active]);
|
|
1427
|
+
}, [active, playAction]);
|
|
1419
1428
|
return /* @__PURE__ */ jsxs2(
|
|
1420
1429
|
VideoPlayerStyles,
|
|
1421
1430
|
{
|