@applicaster/quick-brick-player 15.0.0-rc.98 → 15.1.0-alpha.2915689988
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/PlayNextOverlay/index.tsx +2 -2
- package/src/Player/Utils/index.tsx +9 -9
- package/src/Player/index.tsx +39 -29
- package/src/QuickBrickPlayer.tsx +1 -1
- package/src/Player/hooks/progressStates/__tests__/utils.test.ts +0 -23
- package/src/Player/hooks/progressStates/useLiveProgressState.tsx +0 -78
- package/src/Player/hooks/progressStates/useProgressState.tsx +0 -30
- package/src/Player/hooks/progressStates/useVodProgressState.tsx +0 -115
- package/src/Player/hooks/progressStates/utils.ts +0 -33
- package/src/Player/hooks/useIsCasting.tsx +0 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-player",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.1.0-alpha.2915689988",
|
|
4
4
|
"description": "Quick Brick Player",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@applicaster/quick-brick-mobile-transport-controls": "
|
|
39
|
-
"@applicaster/quick-brick-tv-transport-controls": "15.
|
|
40
|
-
"@applicaster/zapp-react-native-tvos-app": "15.
|
|
41
|
-
"@applicaster/zapp-react-native-ui-components": "15.
|
|
42
|
-
"@applicaster/zapp-react-native-utils": "15.
|
|
38
|
+
"@applicaster/quick-brick-mobile-transport-controls": "14.0.25",
|
|
39
|
+
"@applicaster/quick-brick-tv-transport-controls": "15.1.0-rc.7",
|
|
40
|
+
"@applicaster/zapp-react-native-tvos-app": "15.1.0-alpha.2915689988",
|
|
41
|
+
"@applicaster/zapp-react-native-ui-components": "15.1.0-alpha.2915689988",
|
|
42
|
+
"@applicaster/zapp-react-native-utils": "15.1.0-alpha.2915689988",
|
|
43
43
|
"query-string": "7.1.3",
|
|
44
44
|
"shaka-player": "4.3.5",
|
|
45
45
|
"typeface-montserrat": "^0.0.54",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
5
|
import { PlayNextData } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainer";
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
@@ -32,7 +32,7 @@ export const PlayNextOverlay = ({
|
|
|
32
32
|
playNextData,
|
|
33
33
|
setNextVideoPreloadThresholdPercentage,
|
|
34
34
|
}: Props) => {
|
|
35
|
-
const plugins =
|
|
35
|
+
const { plugins } = usePickFromState(["plugins"]);
|
|
36
36
|
|
|
37
37
|
const OverlayPlugin = getOverlayPlugin(plugins);
|
|
38
38
|
|
|
@@ -3,13 +3,13 @@ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils"
|
|
|
3
3
|
export * from "./Utils";
|
|
4
4
|
|
|
5
5
|
export const getBottomSheetModalIconProps = (theme) => ({
|
|
6
|
-
height: theme
|
|
7
|
-
width: theme
|
|
8
|
-
marginBottom: theme
|
|
9
|
-
marginLeft: theme
|
|
10
|
-
marginRight: theme
|
|
11
|
-
marginTop: theme
|
|
12
|
-
flavour: theme
|
|
6
|
+
height: theme["audio_modal_bottom_sheet_item_icon_height"],
|
|
7
|
+
width: theme["audio_modal_bottom_sheet_item_icon_width"],
|
|
8
|
+
marginBottom: theme["audio_modal_bottom_sheet_item_icon_margin_bottom"],
|
|
9
|
+
marginLeft: theme["audio_modal_bottom_sheet_item_icon_margin_left"],
|
|
10
|
+
marginRight: theme["audio_modal_bottom_sheet_item_icon_margin_right"],
|
|
11
|
+
marginTop: theme["audio_modal_bottom_sheet_item_icon_margin_top"],
|
|
12
|
+
flavour: theme["modal_bottom_sheet_item_icon_flavour"],
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
export const getBottomSheetModalLabelProps = (theme, width: number) => {
|
|
@@ -112,10 +112,10 @@ export const getBottomSheetModalItemProps = (theme, width: number) => {
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
export const getBottomSheetModalSelectedItemIcon = (theme) =>
|
|
115
|
-
theme
|
|
115
|
+
theme["audio_modal_bottom_sheet_item_selected_icon"] || null;
|
|
116
116
|
|
|
117
117
|
export const getBottomSheetModalDefaultItemIcon = (theme) =>
|
|
118
|
-
theme
|
|
118
|
+
theme["audio_modal_bottom_sheet_item_default_icon"] || null;
|
|
119
119
|
|
|
120
120
|
export const selectSleepTitle = (configuration) =>
|
|
121
121
|
configuration.playback_sleep_title;
|
package/src/Player/index.tsx
CHANGED
|
@@ -7,8 +7,12 @@ import * as R from "ramda";
|
|
|
7
7
|
|
|
8
8
|
import { findNodeHandle, StyleSheet, View, ViewStyle } from "react-native";
|
|
9
9
|
|
|
10
|
-
import TransportControlsMobile
|
|
11
|
-
|
|
10
|
+
import TransportControlsMobile, {
|
|
11
|
+
ErrorOverlay,
|
|
12
|
+
} from "@applicaster/quick-brick-mobile-transport-controls";
|
|
13
|
+
import TransportControlsTV, {
|
|
14
|
+
ErrorOverlay as TVErrorOverlay,
|
|
15
|
+
} from "@applicaster/quick-brick-tv-transport-controls";
|
|
12
16
|
|
|
13
17
|
import { AudioPlayer } from "@applicaster/zapp-react-native-ui-components/Components/AudioPlayer";
|
|
14
18
|
import {
|
|
@@ -27,7 +31,6 @@ import {
|
|
|
27
31
|
import { PlayNextOverlay } from "./PlayNextOverlay";
|
|
28
32
|
import { PlayerImageBackground } from "@applicaster/zapp-react-native-ui-components/Components/PlayerImageBackground";
|
|
29
33
|
|
|
30
|
-
import { GENERAL_EVENT } from "@applicaster/zapp-react-native-utils/analyticsUtils/events";
|
|
31
34
|
import { parseLanguageTracks } from "@applicaster/zapp-react-native-utils/playerUtils/configurationUtils";
|
|
32
35
|
import { DEFAULT_COLORS, SEEK_TIME } from "../utils/const";
|
|
33
36
|
import { logger, getScreenAspectRatio } from "../utils";
|
|
@@ -37,7 +40,6 @@ import { getAllAccessibilityProps } from "@applicaster/zapp-react-native-utils/c
|
|
|
37
40
|
import { PlayNextData } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainer";
|
|
38
41
|
import { getTargetScreenDataFromEntry } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useTargetScreenData";
|
|
39
42
|
import { PlayerAnalyticsManager } from "@applicaster/zapp-react-native-utils/analyticsUtils/PlayerAnalyticsManager";
|
|
40
|
-
import { PlayerAnalyticsTrackerI } from "@applicaster/zapp-react-native-utils/analyticsUtils/playerAnalyticsTracker";
|
|
41
43
|
|
|
42
44
|
import { RNPlayerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/nativePlayerManager";
|
|
43
45
|
import {
|
|
@@ -102,6 +104,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
102
104
|
isLive?: boolean;
|
|
103
105
|
seekableDuration?: number;
|
|
104
106
|
displayOverlay?: boolean;
|
|
107
|
+
error: PlayerError | null;
|
|
105
108
|
}
|
|
106
109
|
> {
|
|
107
110
|
public static propTypes = {};
|
|
@@ -121,6 +124,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
121
124
|
isLive?: boolean;
|
|
122
125
|
seekableDuration?: number;
|
|
123
126
|
displayOverlay?: boolean;
|
|
127
|
+
error: PlayerError | null;
|
|
124
128
|
} = {
|
|
125
129
|
// Base required properties from NativePlayerState
|
|
126
130
|
buffering: false,
|
|
@@ -131,7 +135,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
131
135
|
isTabletPortrait: false,
|
|
132
136
|
muted: false,
|
|
133
137
|
showPoster: false,
|
|
134
|
-
|
|
138
|
+
error: null,
|
|
135
139
|
// Extended properties
|
|
136
140
|
audioTrackId: null,
|
|
137
141
|
textTrackId: null,
|
|
@@ -158,20 +162,10 @@ export default class VideoPlayer extends React.Component<
|
|
|
158
162
|
nativePlayerIsReady: false,
|
|
159
163
|
};
|
|
160
164
|
|
|
161
|
-
private _tracker: PlayerAnalyticsTrackerI;
|
|
162
|
-
get analyticsTracker() {
|
|
163
|
-
if (!this._tracker) {
|
|
164
|
-
this._tracker = PlayerAnalyticsManager.getInstance().getTracker(
|
|
165
|
-
this.props.playerId
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return this._tracker;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
165
|
constructor(props) {
|
|
173
166
|
super(props);
|
|
174
167
|
this.onVideoLoadCalled = false; // android
|
|
168
|
+
PlayerAnalyticsManager.getInstance();
|
|
175
169
|
|
|
176
170
|
this.takeParentStyle = isWeb()
|
|
177
171
|
? { width: "100%", flex: "1 1 auto", objectFit: "contain" }
|
|
@@ -185,9 +179,6 @@ export default class VideoPlayer extends React.Component<
|
|
|
185
179
|
componentWillUnmount() {
|
|
186
180
|
this.playbackStarted = false;
|
|
187
181
|
|
|
188
|
-
this.analyticsTracker.handleAnalyticEvent(GENERAL_EVENT.session_end);
|
|
189
|
-
this.onPlayerClosed();
|
|
190
|
-
|
|
191
182
|
if (isAndroidPlatform()) {
|
|
192
183
|
this.disablePiP();
|
|
193
184
|
}
|
|
@@ -195,7 +186,6 @@ export default class VideoPlayer extends React.Component<
|
|
|
195
186
|
|
|
196
187
|
componentDidMount() {
|
|
197
188
|
this.playbackStarted = false;
|
|
198
|
-
this.onPlayerPresented();
|
|
199
189
|
}
|
|
200
190
|
|
|
201
191
|
shouldComponentUpdate(nextProps) {
|
|
@@ -439,14 +429,6 @@ export default class VideoPlayer extends React.Component<
|
|
|
439
429
|
});
|
|
440
430
|
};
|
|
441
431
|
|
|
442
|
-
onPlayerPresented = () => {
|
|
443
|
-
this.analyticsTracker?.handleAnalyticEvent(GENERAL_EVENT.player_presented);
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
onPlayerClosed = () => {
|
|
447
|
-
this.analyticsTracker?.handleAnalyticEvent(GENERAL_EVENT.player_closed);
|
|
448
|
-
};
|
|
449
|
-
|
|
450
432
|
onVideoEnd = () => {
|
|
451
433
|
this.setState({ displayOverlay: !this.state.displayOverlay }, () => {
|
|
452
434
|
if (this.state?.displayOverlay) {
|
|
@@ -462,6 +444,8 @@ export default class VideoPlayer extends React.Component<
|
|
|
462
444
|
|
|
463
445
|
const newError = new PlayerError(error, description);
|
|
464
446
|
|
|
447
|
+
this.setState({ error: newError });
|
|
448
|
+
|
|
465
449
|
return this.props?.listener?.onError(newError);
|
|
466
450
|
};
|
|
467
451
|
|
|
@@ -749,7 +733,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
749
733
|
}
|
|
750
734
|
|
|
751
735
|
renderPlayerContent(playerDimensions: ViewStyle) {
|
|
752
|
-
const { entry, docked } = this.props;
|
|
736
|
+
const { entry, docked, fullscreen } = this.props;
|
|
753
737
|
const { isAd, piped } = this.state;
|
|
754
738
|
|
|
755
739
|
const pluginConfiguration = this.getPluginConfiguration();
|
|
@@ -812,6 +796,20 @@ export default class VideoPlayer extends React.Component<
|
|
|
812
796
|
pluginConfiguration
|
|
813
797
|
);
|
|
814
798
|
|
|
799
|
+
if (this.state.error) {
|
|
800
|
+
return (
|
|
801
|
+
<View style={styles.container}>
|
|
802
|
+
<ErrorOverlay
|
|
803
|
+
error={this.state.error}
|
|
804
|
+
onClose={() => playerManager.close()}
|
|
805
|
+
configuration={pluginConfiguration}
|
|
806
|
+
docked={docked}
|
|
807
|
+
fullscreen={fullscreen}
|
|
808
|
+
/>
|
|
809
|
+
</View>
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
|
|
815
813
|
return (
|
|
816
814
|
<View style={styles.container}>
|
|
817
815
|
<View style={[playerContainerStyles, playerDimensions]}>
|
|
@@ -1346,6 +1344,18 @@ export default class VideoPlayer extends React.Component<
|
|
|
1346
1344
|
style: { ...styles.audio, ...this.takeParentStyle },
|
|
1347
1345
|
};
|
|
1348
1346
|
|
|
1347
|
+
if (this.state.error) {
|
|
1348
|
+
return (
|
|
1349
|
+
<View style={this.takeParentStyle} testID={"player-view"}>
|
|
1350
|
+
<TVErrorOverlay
|
|
1351
|
+
error={this.state.error}
|
|
1352
|
+
onClose={() => playerManager.close()}
|
|
1353
|
+
configuration={this.getPluginConfiguration()}
|
|
1354
|
+
/>
|
|
1355
|
+
</View>
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1349
1359
|
return (
|
|
1350
1360
|
<View style={this.takeParentStyle} testID={"player-view"}>
|
|
1351
1361
|
<TVPlayerView
|
package/src/QuickBrickPlayer.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/acti
|
|
|
7
7
|
import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
8
8
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
9
9
|
import { usePlayerTTS } from "@applicaster/zapp-react-native-utils/playerUtils/usePlayerTTS";
|
|
10
|
-
import { useIsCasting } from "
|
|
10
|
+
import { useIsCasting } from "@applicaster/zapp-react-native-utils/reactHooks/casting";
|
|
11
11
|
|
|
12
12
|
const CHROMECAST_IDENTIFIER = "quick-brick-chromecast-action";
|
|
13
13
|
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { calculateLiveProgressBarTime } from "../utils";
|
|
2
|
-
|
|
3
|
-
describe("Utils", () => {
|
|
4
|
-
describe("calculateLiveProgressBarTime", () => {
|
|
5
|
-
it("Should return 0", () => {
|
|
6
|
-
expect(calculateLiveProgressBarTime(68, 1)).toBe(0);
|
|
7
|
-
|
|
8
|
-
expect(calculateLiveProgressBarTime(68, 0)).toBe(0);
|
|
9
|
-
|
|
10
|
-
expect(calculateLiveProgressBarTime(68, -1)).toBe(0);
|
|
11
|
-
|
|
12
|
-
expect(calculateLiveProgressBarTime(68, -5)).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("Should return equal duration", () => {
|
|
16
|
-
expect(calculateLiveProgressBarTime(68, -100)).toBe(-68);
|
|
17
|
-
|
|
18
|
-
expect(calculateLiveProgressBarTime(68, -68)).toBe(-68);
|
|
19
|
-
|
|
20
|
-
expect(calculateLiveProgressBarTime(68, -105)).toBe(-68);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
import { calculateLiveProgressBarTime, formatTimeDisplay } from "./utils";
|
|
4
|
-
import { ProgressState } from "./useProgressState";
|
|
5
|
-
|
|
6
|
-
// TODO: Must Add check RTL support
|
|
7
|
-
const getSliderValues = (seekableDuration: number, time: number) => {
|
|
8
|
-
const value = calculateLiveProgressBarTime(seekableDuration, time);
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
minimumValue: -seekableDuration,
|
|
12
|
-
maximumValue: 0,
|
|
13
|
-
value: Math.min(0, value),
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const prepareNewState = ({ seekableDuration, time }) => {
|
|
18
|
-
const sliderValues = getSliderValues(seekableDuration, time);
|
|
19
|
-
|
|
20
|
-
const getProgress = (
|
|
21
|
-
seekableDuration: number,
|
|
22
|
-
currentTime: number
|
|
23
|
-
): number => {
|
|
24
|
-
return Math.round((currentTime / seekableDuration) * 100);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const getElapsedTime = (currentTime: number): string => {
|
|
28
|
-
return currentTime === 0
|
|
29
|
-
? ""
|
|
30
|
-
: `-${formatTimeDisplay(Math.abs(currentTime))}`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const getLiveOffsetPercent = (): number =>
|
|
34
|
-
(100 * (sliderValues.value - sliderValues.minimumValue)) /
|
|
35
|
-
(sliderValues.maximumValue - sliderValues.minimumValue);
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
progress: getProgress(seekableDuration, sliderValues.value),
|
|
39
|
-
liveOffsetPercent: getLiveOffsetPercent(),
|
|
40
|
-
time: [getElapsedTime(sliderValues.value), null],
|
|
41
|
-
currentTime: sliderValues.value,
|
|
42
|
-
duration: Math.max(0, seekableDuration),
|
|
43
|
-
sliderValues,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// TODO: Add for `NOW` localization
|
|
48
|
-
export const useLiveProgressState = ({
|
|
49
|
-
playerState: { currentTime, seekableDuration },
|
|
50
|
-
}): [ProgressState, (seek: number) => void] => {
|
|
51
|
-
const stateRef = React.useRef<ProgressState>({
|
|
52
|
-
progress: 0,
|
|
53
|
-
liveOffsetPercent: 0,
|
|
54
|
-
time: ["--:--", "--:--"],
|
|
55
|
-
currentTime: 0,
|
|
56
|
-
duration: 0,
|
|
57
|
-
sliderValues: {
|
|
58
|
-
minimumValue: 0,
|
|
59
|
-
maximumValue: 0,
|
|
60
|
-
value: 0,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const updateState = React.useCallback(
|
|
65
|
-
(seekTime: number): void => {
|
|
66
|
-
if (seekTime == null || seekableDuration == null) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
stateRef.current = prepareNewState({ seekableDuration, time: -seekTime });
|
|
71
|
-
},
|
|
72
|
-
[seekableDuration]
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
updateState(currentTime);
|
|
76
|
-
|
|
77
|
-
return [stateRef.current, updateState];
|
|
78
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useLiveProgressState } from "./useLiveProgressState";
|
|
2
|
-
import { useVodProgressState } from "./useVodProgressState";
|
|
3
|
-
|
|
4
|
-
export type ProgressState = {
|
|
5
|
-
liveOffsetPercent?: number;
|
|
6
|
-
progress: number;
|
|
7
|
-
time: string[];
|
|
8
|
-
currentTime: number;
|
|
9
|
-
duration: number;
|
|
10
|
-
sliderValues: { minimumValue: number; maximumValue: number; value: number };
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// TODO: Try refactor to remove code duplication
|
|
14
|
-
export const useProgressState = ({
|
|
15
|
-
playerState: { seekableDuration, duration, isLive },
|
|
16
|
-
remainingTimeDisplay = false,
|
|
17
|
-
currentTime,
|
|
18
|
-
}): [ProgressState, (seek) => void] => {
|
|
19
|
-
const liveData: [ProgressState, (seek: number) => void] =
|
|
20
|
-
useLiveProgressState({
|
|
21
|
-
playerState: { currentTime, seekableDuration },
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const vodData: [ProgressState, (seek) => void] = useVodProgressState({
|
|
25
|
-
playerState: { currentTime, duration },
|
|
26
|
-
remainingTimeDisplay,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return isLive ? liveData : vodData;
|
|
30
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
|
|
3
|
-
import { useAppState } from "@applicaster/zapp-react-native-utils/reactHooks/app";
|
|
4
|
-
import { isApplePlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
5
|
-
|
|
6
|
-
const CHROMECAST_IDENTIFIER = "quick-brick-chromecast-action";
|
|
7
|
-
|
|
8
|
-
const fakeEntry: any = {
|
|
9
|
-
title: "Chromecast use is casting fake entry",
|
|
10
|
-
id: "quick-brick-use-is-casting-fake-entry",
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Returns the cast action state connection status, does not update when app is in background on Apple platforms
|
|
15
|
-
* On other platforms, it continues to check the cast action state even when the app is in background
|
|
16
|
-
*/
|
|
17
|
-
export const useIsCasting = () => {
|
|
18
|
-
const actionContext = useActions(CHROMECAST_IDENTIFIER);
|
|
19
|
-
const appState = useAppState();
|
|
20
|
-
const isAppInForeground = appState === "active";
|
|
21
|
-
const shouldOnlyUpdateInForeground = isApplePlatform();
|
|
22
|
-
|
|
23
|
-
const [castActionState, setCastActionState] = React.useState(
|
|
24
|
-
!actionContext ? null : actionContext.initialEntryState(fakeEntry)
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
React.useEffect(() => {
|
|
28
|
-
if (!shouldOnlyUpdateInForeground || isAppInForeground) {
|
|
29
|
-
if (actionContext && castActionState === null) {
|
|
30
|
-
setCastActionState(actionContext.initialEntryState(fakeEntry));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}, [
|
|
34
|
-
actionContext,
|
|
35
|
-
setCastActionState,
|
|
36
|
-
isAppInForeground,
|
|
37
|
-
shouldOnlyUpdateInForeground,
|
|
38
|
-
]);
|
|
39
|
-
|
|
40
|
-
React.useEffect(() => {
|
|
41
|
-
if (typeof actionContext?.addListener === "function") {
|
|
42
|
-
return actionContext?.addListener(String(fakeEntry.id), (state) => {
|
|
43
|
-
// Only check foreground state on Apple platforms
|
|
44
|
-
if (!shouldOnlyUpdateInForeground || isAppInForeground) {
|
|
45
|
-
setCastActionState(state);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}, [
|
|
50
|
-
setCastActionState,
|
|
51
|
-
actionContext,
|
|
52
|
-
isAppInForeground,
|
|
53
|
-
shouldOnlyUpdateInForeground,
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
return !!castActionState?.connected;
|
|
57
|
-
};
|