@applicaster/quick-brick-player 15.0.0-rc.5 → 15.0.0-rc.50
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/package.json +6 -6
- package/src/Player/AudioLayer/AudioPlayerWrapper.tsx +20 -8
- package/src/Player/AudioLayer/Layout/DockedControls/index.tsx +78 -65
- package/src/Player/AudioLayer/Layout/MobileLayout.tsx +1 -6
- package/src/Player/AudioLayer/Layout/PlayerImage/index.tsx +27 -25
- package/src/Player/AudioLayer/Layout/PlayerImage/styles.ts +6 -1
- package/src/Player/AudioLayer/Layout/TabletLandscapeLayout.tsx +5 -8
- package/src/Player/AudioLayer/Layout/TabletPortraitLayout.tsx +1 -6
- package/src/Player/AudioLayer/utils.ts +1 -27
- package/src/Player/PlayNextOverlay/index.tsx +2 -2
- package/src/Player/PlayerModal/PlayerModal.tsx +16 -15
- package/src/Player/PlayerModal/VideoPlayerModal.tsx +138 -120
- package/src/Player/PlayerModal/consts/index.ts +2 -19
- package/src/Player/PlayerModal/hooks/index.ts +115 -139
- package/src/Player/PlayerModal/styles.ts +5 -0
- package/src/Player/PlayerModal/utils/index.ts +111 -0
- package/src/Player/PlayerView/types.ts +1 -2
- package/src/Player/Utils/index.tsx +9 -9
- package/src/Player/hooks/progressStates/__tests__/utils.test.ts +23 -0
- package/src/Player/hooks/progressStates/useLiveProgressState.tsx +78 -0
- package/src/Player/hooks/progressStates/useProgressState.tsx +30 -0
- package/src/Player/hooks/progressStates/useVodProgressState.tsx +115 -0
- package/src/Player/hooks/progressStates/utils.ts +33 -0
- package/src/Player/index.tsx +559 -357
- package/src/utils/dimensions.ts +29 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/logger.ts +6 -0
- package/src/utils/playerHelpers.ts +11 -0
- package/src/utils/playerStyles.ts +50 -0
- package/src/Player/AudioLayer/Layout/PlayerImage/AnimatedImage.tsx +0 -82
- package/src/Player/AudioLayer/Layout/PlayerImage/hooks/index.ts +0 -1
- package/src/Player/AudioLayer/Layout/PlayerImage/hooks/useChangePlayerState.ts +0 -99
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { formatTimeDisplay } from "./utils";
|
|
4
|
+
import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
|
|
5
|
+
import { ProgressState } from "./useProgressState";
|
|
6
|
+
|
|
7
|
+
// TODO: Refactor if needed, code was aligned to new structure only
|
|
8
|
+
|
|
9
|
+
const getSliderValues = (duration: number, time: number, isRTL: boolean) => {
|
|
10
|
+
const minimumValue = 0;
|
|
11
|
+
|
|
12
|
+
// Default max value should be greater than duration due to RTL thumb animation
|
|
13
|
+
const maximumValue = duration || 9999;
|
|
14
|
+
const initValue = isRTL ? maximumValue : minimumValue;
|
|
15
|
+
const currentValue = isRTL ? duration - time : time;
|
|
16
|
+
const progressValue = !duration ? initValue : currentValue;
|
|
17
|
+
const timeValue = !duration ? minimumValue : time;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
minimumValue,
|
|
21
|
+
maximumValue,
|
|
22
|
+
value: Math.max(0, progressValue),
|
|
23
|
+
timeValue: Math.max(0, timeValue),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const prepareNewState = ({ duration, time, remainingTimeDisplay, isRTL }) => {
|
|
28
|
+
const sliderValues = getSliderValues(duration, time, isRTL);
|
|
29
|
+
|
|
30
|
+
const getProgress = (duration, currentTime): number => {
|
|
31
|
+
return Math.round((currentTime / duration) * 100);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getElapsedTime = (currentTime): string => {
|
|
35
|
+
return formatTimeDisplay(currentTime);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getRemainingTime = (duration, currentTime): string => {
|
|
39
|
+
if (isNaN(duration)) {
|
|
40
|
+
return "--:--";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return formatTimeDisplay(duration - currentTime);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const remaining = getRemainingTime(duration, sliderValues.value);
|
|
47
|
+
|
|
48
|
+
const remainingTimeState = remainingTimeDisplay
|
|
49
|
+
? `-${remaining}`
|
|
50
|
+
: formatTimeDisplay(duration);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
progress: getProgress(duration, sliderValues.value),
|
|
54
|
+
time: [getElapsedTime(sliderValues.timeValue), remainingTimeState],
|
|
55
|
+
currentTime: sliderValues.timeValue,
|
|
56
|
+
duration: Math.max(0, duration),
|
|
57
|
+
sliderValues,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const useVodProgressState = ({
|
|
62
|
+
remainingTimeDisplay = false,
|
|
63
|
+
playerState: { currentTime, duration },
|
|
64
|
+
}): [ProgressState, (seek) => void] => {
|
|
65
|
+
const [state, setState] = React.useState<ProgressState>({
|
|
66
|
+
progress: 0,
|
|
67
|
+
time: ["--:--", "--:--"],
|
|
68
|
+
currentTime: 0,
|
|
69
|
+
duration: 0,
|
|
70
|
+
sliderValues: {
|
|
71
|
+
minimumValue: 0,
|
|
72
|
+
maximumValue: 0,
|
|
73
|
+
value: 0,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const isRTL = useIsRTL();
|
|
78
|
+
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
if (currentTime == null || duration == null) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setState(
|
|
85
|
+
prepareNewState({
|
|
86
|
+
duration,
|
|
87
|
+
time: currentTime,
|
|
88
|
+
remainingTimeDisplay,
|
|
89
|
+
isRTL,
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
}, [currentTime, duration, isRTL, remainingTimeDisplay]);
|
|
93
|
+
|
|
94
|
+
const updateState = React.useCallback(
|
|
95
|
+
(seekTime?: number): void => {
|
|
96
|
+
if (seekTime == null || duration == null) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const time =
|
|
101
|
+
(seekTime || seekTime === 0) && Math.abs(seekTime - currentTime) > 1
|
|
102
|
+
? seekTime
|
|
103
|
+
: currentTime;
|
|
104
|
+
|
|
105
|
+
if (duration && (time || time === 0)) {
|
|
106
|
+
setState(
|
|
107
|
+
prepareNewState({ duration, time, remainingTimeDisplay, isRTL })
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[duration, currentTime, remainingTimeDisplay, isRTL]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return [state, updateState];
|
|
115
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const prependZeroIfNeeded = (value) => {
|
|
2
|
+
const s = typeof value === "number" ? String(value) : String(value ?? "");
|
|
3
|
+
|
|
4
|
+
return `0${s}`.slice(-2);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const calculateLiveProgressBarTime = (duration, time) => {
|
|
8
|
+
const minimumLiveOffsetStart = -5;
|
|
9
|
+
|
|
10
|
+
if (time < minimumLiveOffsetStart && time > -duration) {
|
|
11
|
+
// -67 < -5 && -67 > -68
|
|
12
|
+
return time;
|
|
13
|
+
} else if (time <= -duration) {
|
|
14
|
+
return -duration;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return 0;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function formatTimeDisplay(durationInSeconds) {
|
|
21
|
+
const hours = Math.floor(durationInSeconds / 60 / 60);
|
|
22
|
+
const minutes = Math.floor((durationInSeconds - hours * 60 * 60) / 60);
|
|
23
|
+
|
|
24
|
+
const seconds = Math.floor(
|
|
25
|
+
durationInSeconds - hours * 60 * 60 - minutes * 60
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const hr = prependZeroIfNeeded(hours);
|
|
29
|
+
const mn = prependZeroIfNeeded(minutes);
|
|
30
|
+
const sc = prependZeroIfNeeded(seconds);
|
|
31
|
+
|
|
32
|
+
return `${hours ? `${hr}:` : ""}${mn || "00"}:${sc}`;
|
|
33
|
+
}
|