@applicaster/quick-brick-player 13.0.0-alpha.6944415045 → 13.0.0-alpha.7100577251
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 +103 -120
- package/src/Player/AudioLayer/Layout/DefaultLayout.tsx +3 -2
- package/src/Player/AudioLayer/Layout/defaultLayoutsConts.ts +2 -2
- package/src/Player/AudioLayer/SleepTimerManager.ts +119 -0
- package/src/Player/AudioLayer/SpeedManager.ts +52 -0
- package/src/Player/index.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-player",
|
|
3
|
-
"version": "13.0.0-alpha.
|
|
3
|
+
"version": "13.0.0-alpha.7100577251",
|
|
4
4
|
"description": "Quick Brick Player",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@applicaster/quick-brick-mobile-transport-controls": "13.0.0-
|
|
40
|
-
"@applicaster/quick-brick-tv-transport-controls": "13.0.0-rc.
|
|
41
|
-
"@applicaster/zapp-react-native-tvos-app": "13.0.0-alpha.
|
|
42
|
-
"@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.
|
|
43
|
-
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.
|
|
39
|
+
"@applicaster/quick-brick-mobile-transport-controls": "13.0.0-rc.28",
|
|
40
|
+
"@applicaster/quick-brick-tv-transport-controls": "13.0.0-rc.31",
|
|
41
|
+
"@applicaster/zapp-react-native-tvos-app": "13.0.0-alpha.7100577251",
|
|
42
|
+
"@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.7100577251",
|
|
43
|
+
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.7100577251",
|
|
44
44
|
"keymirror": "^0.1.1",
|
|
45
45
|
"query-string": "7.1.3",
|
|
46
46
|
"react-native-web-linear-gradient": "1.1.2",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { ViewStyle, View } from "react-native";
|
|
2
|
+
import { ViewStyle, View, Dimensions as ScreenDimensions } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { SafeAreaView, Edge } from "react-native-safe-area-context";
|
|
5
5
|
import { usePlayerState } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerState";
|
|
@@ -17,13 +17,7 @@ import { PlayerDetails } from "@applicaster/zapp-react-native-ui-components/Comp
|
|
|
17
17
|
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
18
18
|
import { useEffect, useState } from "react";
|
|
19
19
|
import { MagicBG } from "./MagicBG";
|
|
20
|
-
import {
|
|
21
|
-
formatSpeed,
|
|
22
|
-
hasDatePassed,
|
|
23
|
-
loadItemsFromStorage,
|
|
24
|
-
NAMESPACE,
|
|
25
|
-
} from "./utils";
|
|
26
|
-
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
20
|
+
import { formatSpeed } from "./utils";
|
|
27
21
|
import { addQueryParam, getLiveUrl } from "../Utils";
|
|
28
22
|
import { useTitleSummaryOverlay } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerTitleSummaryOverlay";
|
|
29
23
|
import {
|
|
@@ -33,6 +27,20 @@ import {
|
|
|
33
27
|
} from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
|
|
34
28
|
import { PADDING_HORIZONTAL } from "./Layout/defaultLayoutsConts";
|
|
35
29
|
import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
30
|
+
import {
|
|
31
|
+
speed_0_8,
|
|
32
|
+
speed_1,
|
|
33
|
+
speed_1_2,
|
|
34
|
+
speed_1_5,
|
|
35
|
+
speed_2,
|
|
36
|
+
} from "@applicaster/quick-brick-mobile-transport-controls";
|
|
37
|
+
import {
|
|
38
|
+
SleepTimerController,
|
|
39
|
+
SleepTimerState,
|
|
40
|
+
SLEEP_TIMER_OFF,
|
|
41
|
+
} from "./SleepTimerManager";
|
|
42
|
+
import { SpeedController, PlaybackSpeed, DEFAULT_SPEED } from "./SpeedManager";
|
|
43
|
+
import { imageSrcFromMediaItem } from "@applicaster/zapp-react-native-utils/configurationUtils";
|
|
36
44
|
|
|
37
45
|
const { log_debug } = createLogger({
|
|
38
46
|
subsystem: "UIComponent",
|
|
@@ -71,8 +79,7 @@ type Props = {
|
|
|
71
79
|
isTabletPortrait?: boolean;
|
|
72
80
|
};
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
(height / 9) * 16;
|
|
82
|
+
const { width: SCREEN_WIDTH } = ScreenDimensions.get("screen");
|
|
76
83
|
|
|
77
84
|
const Styles = {
|
|
78
85
|
mainContainer: (style: ViewStyle) => {
|
|
@@ -98,7 +105,11 @@ const Styles = {
|
|
|
98
105
|
height: 96,
|
|
99
106
|
marginHorizontal: 24,
|
|
100
107
|
},
|
|
101
|
-
playerDetails: {
|
|
108
|
+
playerDetails: {
|
|
109
|
+
marginTop: 60,
|
|
110
|
+
alignSelf: "center",
|
|
111
|
+
width: SCREEN_WIDTH - PADDING_HORIZONTAL * 2,
|
|
112
|
+
},
|
|
102
113
|
|
|
103
114
|
linearGradient: {
|
|
104
115
|
flex: 1,
|
|
@@ -132,11 +143,11 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
132
143
|
} = props;
|
|
133
144
|
|
|
134
145
|
const speeds = [
|
|
135
|
-
{ asset: configuration["speed_0_8"], value: 0.8 },
|
|
136
|
-
{ asset: configuration["speed_1"], value: 1.0 },
|
|
137
|
-
{ asset: configuration["speed_1_2"], value: 1.2 },
|
|
138
|
-
{ asset: configuration["speed_1_5"], value: 1.5 },
|
|
139
|
-
{ asset: configuration["speed_2"], value: 2.0 },
|
|
146
|
+
{ asset: configuration["speed_0_8"] || speed_0_8, value: 0.8 },
|
|
147
|
+
{ asset: configuration["speed_1"] || speed_1, value: 1.0 },
|
|
148
|
+
{ asset: configuration["speed_1_2"] || speed_1_2, value: 1.2 },
|
|
149
|
+
{ asset: configuration["speed_1_5"] || speed_1_5, value: 1.5 },
|
|
150
|
+
{ asset: configuration["speed_2"] || speed_2, value: 2.0 },
|
|
140
151
|
];
|
|
141
152
|
|
|
142
153
|
const isTablet = useIsTablet();
|
|
@@ -154,17 +165,29 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
154
165
|
configuration?.audio_live_player_update_interval
|
|
155
166
|
);
|
|
156
167
|
|
|
157
|
-
const [
|
|
158
|
-
|
|
159
|
-
value: 1.0,
|
|
160
|
-
});
|
|
168
|
+
const [sleepTimerManager, setSleepTimerManager] =
|
|
169
|
+
useState<SleepTimerController | null>(null);
|
|
161
170
|
|
|
162
|
-
const [
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
const [speedManager, setSpeedManager] = useState<SpeedController | null>(
|
|
172
|
+
null
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (player) {
|
|
177
|
+
setSleepTimerManager(new SleepTimerController(player));
|
|
178
|
+
setSpeedManager(new SpeedController(player));
|
|
179
|
+
} else {
|
|
180
|
+
setSleepTimerManager(null);
|
|
181
|
+
setSpeedManager(null);
|
|
182
|
+
}
|
|
183
|
+
}, [player]);
|
|
184
|
+
|
|
185
|
+
const [playbackSpeed, setPlaybackSpeed] =
|
|
186
|
+
useState<PlaybackSpeed>(DEFAULT_SPEED);
|
|
166
187
|
|
|
167
|
-
const [
|
|
188
|
+
const [sleepTimerState, setSleepTimerState] = useState<SleepTimerState>(
|
|
189
|
+
new SleepTimerState(SLEEP_TIMER_OFF, 0)
|
|
190
|
+
);
|
|
168
191
|
|
|
169
192
|
const [defaultDimensions, setDefaultDimensions] =
|
|
170
193
|
React.useState<Dimensions>(undefined);
|
|
@@ -189,82 +212,27 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
189
212
|
if (!defaultDimensions) setDefaultDimensions({ width, height });
|
|
190
213
|
};
|
|
191
214
|
|
|
192
|
-
const cancelSleepTimer = async () => {
|
|
193
|
-
player?.cancelSleepTimer();
|
|
194
|
-
|
|
195
|
-
setSleepTimer({
|
|
196
|
-
label: "playback_sleep_off_label",
|
|
197
|
-
value: 0,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
setSleepTimerDate(0);
|
|
201
|
-
|
|
202
|
-
await localStorage.removeItem("sleep", NAMESPACE);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const startSleepTimer = (timerValue: number) => {
|
|
206
|
-
try {
|
|
207
|
-
const currentDate = new Date();
|
|
208
|
-
const futureDate = new Date(currentDate.getTime() + timerValue * 60000);
|
|
209
|
-
const futureSleepDate = futureDate.getTime();
|
|
210
|
-
|
|
211
|
-
player?.cancelSleepTimer();
|
|
212
|
-
|
|
213
|
-
player?.startSleepTimer(futureSleepDate);
|
|
214
|
-
|
|
215
|
-
return futureSleepDate;
|
|
216
|
-
} catch (e) {
|
|
217
|
-
return 0;
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const handleSleep = async (
|
|
222
|
-
timerValue: number,
|
|
223
|
-
currentFutureSleepDate = null
|
|
224
|
-
) => {
|
|
225
|
-
if (currentFutureSleepDate) {
|
|
226
|
-
if (hasDatePassed(currentFutureSleepDate)) {
|
|
227
|
-
await cancelSleepTimer();
|
|
228
|
-
|
|
229
|
-
return 0;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return currentFutureSleepDate;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (timerValue === 0) {
|
|
236
|
-
await cancelSleepTimer();
|
|
237
|
-
|
|
238
|
-
return timerValue;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return startSleepTimer(timerValue);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
215
|
useEffect(() => {
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (playerState.isReadyToPlay && speed) {
|
|
249
|
-
setPlaybackSpeed(speed);
|
|
250
|
-
player?.setPlaybackRate(speed.value);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
216
|
+
const sleepSubscription =
|
|
217
|
+
sleepTimerManager?.sleepTimerState$.subscribe(setSleepTimerState);
|
|
253
218
|
|
|
254
|
-
const
|
|
255
|
-
|
|
219
|
+
const speedSubscription =
|
|
220
|
+
speedManager?.playbackSpeed$.subscribe(setPlaybackSpeed);
|
|
256
221
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const sleepTimerDate = await handleSleep(sleep.value, futureSleepDate);
|
|
261
|
-
setSleepTimerDate(sleepTimerDate);
|
|
262
|
-
}
|
|
222
|
+
return () => {
|
|
223
|
+
sleepSubscription?.unsubscribe();
|
|
224
|
+
speedSubscription?.unsubscribe();
|
|
263
225
|
};
|
|
226
|
+
}, [sleepTimerManager, speedManager]);
|
|
227
|
+
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (!playerState.isReadyToPlay) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
264
232
|
|
|
265
|
-
loadSpeed()
|
|
266
|
-
loadSleep()
|
|
267
|
-
}, [playerState.isReadyToPlay]);
|
|
233
|
+
void speedManager?.loadSpeed();
|
|
234
|
+
void sleepTimerManager?.loadSleep();
|
|
235
|
+
}, [playerState.isReadyToPlay, speedManager, sleepTimerManager]);
|
|
268
236
|
|
|
269
237
|
const getValue = (key: string, stylesObj: {}) =>
|
|
270
238
|
R.propOr(null, key, stylesObj);
|
|
@@ -292,7 +260,7 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
292
260
|
|
|
293
261
|
const onPlaybackButtonPress = React.useCallback(() => {
|
|
294
262
|
if (playerState.isBuffering) return;
|
|
295
|
-
playerState.isPaused ? player?.play() : player
|
|
263
|
+
playerState.isPaused ? player?.play() : player?.pause();
|
|
296
264
|
}, [playerState, player]);
|
|
297
265
|
|
|
298
266
|
const seekDuration = toNumberWithDefault(10, value("seek_duration"));
|
|
@@ -307,26 +275,16 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
307
275
|
|
|
308
276
|
const onSpeedSelect = React.useCallback(
|
|
309
277
|
async (item) => {
|
|
310
|
-
setPlaybackSpeed(item);
|
|
311
|
-
player.setPlaybackRate(item.value);
|
|
312
|
-
await localStorage.setItem("speed", item, NAMESPACE);
|
|
278
|
+
await speedManager?.setPlaybackSpeed(item);
|
|
313
279
|
},
|
|
314
|
-
[
|
|
280
|
+
[speedManager]
|
|
315
281
|
);
|
|
316
282
|
|
|
317
283
|
const onSleepSelect = React.useCallback(
|
|
318
284
|
async (item) => {
|
|
319
|
-
setSleepTimer(item);
|
|
320
|
-
const futureSleepDate = await handleSleep(item.value);
|
|
321
|
-
setSleepTimerDate(futureSleepDate);
|
|
322
|
-
|
|
323
|
-
await localStorage.setItem(
|
|
324
|
-
"sleep",
|
|
325
|
-
{ ...item, futureSleepDate },
|
|
326
|
-
NAMESPACE
|
|
327
|
-
);
|
|
285
|
+
await sleepTimerManager?.setSleepTimer(item);
|
|
328
286
|
},
|
|
329
|
-
[
|
|
287
|
+
[sleepTimerManager]
|
|
330
288
|
);
|
|
331
289
|
|
|
332
290
|
const onSpeedButtonPress = React.useCallback(() => {
|
|
@@ -341,15 +299,24 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
341
299
|
supportedOrientations: ["portrait"],
|
|
342
300
|
},
|
|
343
301
|
});
|
|
344
|
-
}, [
|
|
302
|
+
}, [
|
|
303
|
+
playbackSpeed,
|
|
304
|
+
setPlaybackSpeed,
|
|
305
|
+
navigator,
|
|
306
|
+
onSpeedSelect,
|
|
307
|
+
configuration["playback_speed_title"],
|
|
308
|
+
]);
|
|
345
309
|
|
|
346
310
|
const onSleepButtonPress = React.useCallback(() => {
|
|
347
311
|
navigator.openModalBottomSheet({
|
|
348
312
|
modalBottomSheetContentProps: {
|
|
349
313
|
items: [
|
|
350
|
-
{
|
|
314
|
+
{
|
|
315
|
+
label: configuration["playback_sleep_off_label"],
|
|
316
|
+
value: 0,
|
|
317
|
+
},
|
|
351
318
|
].concat(sleeps),
|
|
352
|
-
current_selection:
|
|
319
|
+
current_selection: sleepTimerState.timer,
|
|
353
320
|
onPress: onSleepSelect,
|
|
354
321
|
title: configuration["playback_sleep_title"],
|
|
355
322
|
},
|
|
@@ -357,7 +324,21 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
357
324
|
supportedOrientations: ["portrait"],
|
|
358
325
|
},
|
|
359
326
|
});
|
|
360
|
-
}, [
|
|
327
|
+
}, [
|
|
328
|
+
navigator,
|
|
329
|
+
sleepTimerState.timer,
|
|
330
|
+
configuration["playback_sleep_title"],
|
|
331
|
+
configuration["playback_sleep_off_label"],
|
|
332
|
+
onSleepSelect,
|
|
333
|
+
]);
|
|
334
|
+
|
|
335
|
+
// This method does not actually cancel the sleep timer
|
|
336
|
+
// (and should not to avoid race condition),
|
|
337
|
+
// it just performs the cleanup when timer expires
|
|
338
|
+
// TODO: rename it in code above
|
|
339
|
+
const cancelSleepTimer = React.useCallback(() => {
|
|
340
|
+
sleepTimerManager?.onTimerExpired();
|
|
341
|
+
}, [sleepTimerManager]);
|
|
361
342
|
|
|
362
343
|
const onCloseVideoModal = React.useCallback(() => {
|
|
363
344
|
playerManager.close();
|
|
@@ -406,9 +387,11 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
406
387
|
onSleepButtonPress={onSleepButtonPress}
|
|
407
388
|
playbackSpeedName={formatSpeed(playbackSpeed.value)}
|
|
408
389
|
playbackSleepName={
|
|
409
|
-
|
|
390
|
+
sleepTimerState.timer.value === 0
|
|
391
|
+
? "sleep_timer"
|
|
392
|
+
: "sleep_timer_active"
|
|
410
393
|
}
|
|
411
|
-
sleepTimerDate={
|
|
394
|
+
sleepTimerDate={sleepTimerState.timerDate}
|
|
412
395
|
cancelSleepTimer={cancelSleepTimer}
|
|
413
396
|
onSkipLive={onSkipLive}
|
|
414
397
|
onCloseVideoModal={onCloseVideoModal}
|
|
@@ -458,12 +441,12 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
|
|
|
458
441
|
playNextData,
|
|
459
442
|
onSkipStart,
|
|
460
443
|
onSkipLive,
|
|
461
|
-
|
|
462
|
-
|
|
444
|
+
sleepTimerState.timer.value,
|
|
445
|
+
sleepTimerState.timerDate,
|
|
463
446
|
]);
|
|
464
447
|
|
|
465
448
|
if (configuration.magic_background) {
|
|
466
|
-
const baseUrl = entry
|
|
449
|
+
const baseUrl = imageSrcFromMediaItem(entry, null);
|
|
467
450
|
|
|
468
451
|
const queryParamName =
|
|
469
452
|
configuration.audio_player_background_image_query || "width";
|
|
@@ -120,8 +120,8 @@ const Styles = {
|
|
|
120
120
|
(startComponentsAnimation && isActiveGesture) || docked
|
|
121
121
|
? 0
|
|
122
122
|
: isTablet
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
? 24
|
|
124
|
+
: 10,
|
|
125
125
|
}),
|
|
126
126
|
|
|
127
127
|
paddingHorizontal: {
|
|
@@ -375,6 +375,7 @@ export default function DefaultLayout(props: LayoutProps) {
|
|
|
375
375
|
>
|
|
376
376
|
<PlayerImageBackground
|
|
377
377
|
entry={entry}
|
|
378
|
+
docked={docked}
|
|
378
379
|
style={Styles.backgroundImageContainer(dimensions, isTablet)}
|
|
379
380
|
imageStyle={Styles.backgroundImageContainerImageStyle(
|
|
380
381
|
isTablet,
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { BehaviorSubject } from "rxjs";
|
|
2
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
|
+
import { Player } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/player";
|
|
5
|
+
import { hasDatePassed, NAMESPACE } from "./utils";
|
|
6
|
+
|
|
7
|
+
const { log_debug, log_error } = createLogger({
|
|
8
|
+
subsystem: "Player",
|
|
9
|
+
category: "SleepTimerManager",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type SleepTimer = {
|
|
13
|
+
label: string;
|
|
14
|
+
// interval in minutes for UI at the moment when timer was first started
|
|
15
|
+
value: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const SLEEP_TIMER_OFF: SleepTimer = {
|
|
19
|
+
label: "playback_sleep_off_label",
|
|
20
|
+
value: 0,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class SleepTimerState {
|
|
24
|
+
constructor(
|
|
25
|
+
public timer: SleepTimer,
|
|
26
|
+
public timerDate: number
|
|
27
|
+
) {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SLEEP_PREFERENCE_KEY = "sleep";
|
|
31
|
+
|
|
32
|
+
export class SleepTimerController {
|
|
33
|
+
private sleepTimerStateSubject = new BehaviorSubject<SleepTimerState>(
|
|
34
|
+
new SleepTimerState(SLEEP_TIMER_OFF, 0)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
constructor(private player: Player) {}
|
|
38
|
+
|
|
39
|
+
get sleepTimerState$() {
|
|
40
|
+
return this.sleepTimerStateSubject.asObservable();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async scheduleSleep(sleepDate): Promise<boolean> {
|
|
44
|
+
log_debug(`Setting sleep interval to ${sleepDate}`);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
this.player.cancelSleepTimer?.();
|
|
48
|
+
this.player.startSleepTimer?.(sleepDate);
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
log_error("Failed to start sleep timer", { error: e.message });
|
|
53
|
+
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async setSleepTimer(item: SleepTimer) {
|
|
59
|
+
// User has selected Off state
|
|
60
|
+
if (item.value === 0) {
|
|
61
|
+
log_debug("Cancelling sleep timer");
|
|
62
|
+
this.player.cancelSleepTimer?.();
|
|
63
|
+
|
|
64
|
+
return this.onTimerExpired();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
log_debug(`Starting sleep timer in ${item.value} minutes`);
|
|
68
|
+
|
|
69
|
+
const futureSleepDate = Date.now() + item.value * 60000;
|
|
70
|
+
|
|
71
|
+
if (await this.scheduleSleep(futureSleepDate)) {
|
|
72
|
+
await localStorage.setItem(
|
|
73
|
+
SLEEP_PREFERENCE_KEY,
|
|
74
|
+
{ ...item, futureSleepDate },
|
|
75
|
+
NAMESPACE
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
this.sleepTimerStateSubject.next(
|
|
79
|
+
new SleepTimerState(item, futureSleepDate)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async onTimerExpired() {
|
|
85
|
+
await localStorage.removeItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
|
|
86
|
+
|
|
87
|
+
this.sleepTimerStateSubject.next(new SleepTimerState(SLEEP_TIMER_OFF, 0));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async loadSleep() {
|
|
91
|
+
const sleep = await localStorage.getItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
|
|
92
|
+
|
|
93
|
+
if (!sleep) return;
|
|
94
|
+
|
|
95
|
+
const { futureSleepDate, ...rest } = sleep;
|
|
96
|
+
|
|
97
|
+
if (!futureSleepDate || hasDatePassed(futureSleepDate)) {
|
|
98
|
+
log_debug("Sleep date has already passed");
|
|
99
|
+
await localStorage.removeItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
|
|
100
|
+
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (await this.scheduleSleep(futureSleepDate)) {
|
|
105
|
+
log_debug(`Sleep state restored, will go to sleep at ${futureSleepDate}`);
|
|
106
|
+
|
|
107
|
+
this.sleepTimerStateSubject.next(
|
|
108
|
+
new SleepTimerState(rest as SleepTimer, futureSleepDate)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Will be called if user closed the player explicitly.
|
|
114
|
+
// TODO: check if it will be called on Android when we need.
|
|
115
|
+
// Probably we will have to handle it on native instead.
|
|
116
|
+
public static async onPlayerDestroy() {
|
|
117
|
+
await localStorage.removeItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BehaviorSubject } from "rxjs";
|
|
2
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
|
+
import { Player } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/player";
|
|
5
|
+
import { NAMESPACE } from "./utils";
|
|
6
|
+
|
|
7
|
+
const { log_debug } = createLogger({
|
|
8
|
+
subsystem: "Player",
|
|
9
|
+
category: "PlaybackSpeedManager",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type PlaybackSpeed = {
|
|
13
|
+
asset: string;
|
|
14
|
+
value: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const SPEED_PREFERENCE_KEY = "speed";
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_SPEED: PlaybackSpeed = {
|
|
20
|
+
asset: "speed_1",
|
|
21
|
+
value: 1.0,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// todo: should not be applied to live streams
|
|
25
|
+
export class SpeedController {
|
|
26
|
+
private playbackSpeedSubject = new BehaviorSubject<PlaybackSpeed>(
|
|
27
|
+
DEFAULT_SPEED
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
constructor(private player: Player) {}
|
|
31
|
+
|
|
32
|
+
get playbackSpeed$() {
|
|
33
|
+
return this.playbackSpeedSubject.asObservable();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async loadSpeed() {
|
|
37
|
+
const speed = await localStorage.getItem(SPEED_PREFERENCE_KEY, NAMESPACE);
|
|
38
|
+
|
|
39
|
+
// checking for value in case we will pull empty or broken object
|
|
40
|
+
if (speed && speed.value) {
|
|
41
|
+
this.playbackSpeedSubject.next(speed);
|
|
42
|
+
this.player.setPlaybackRate?.(speed.value);
|
|
43
|
+
log_debug(`Speed loaded: ${speed}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async setPlaybackSpeed(speed: PlaybackSpeed) {
|
|
48
|
+
await localStorage.setItem(SPEED_PREFERENCE_KEY, speed, NAMESPACE);
|
|
49
|
+
this.playbackSpeedSubject.next(speed);
|
|
50
|
+
this.player.setPlaybackRate?.(speed.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/Player/index.tsx
CHANGED
|
@@ -918,8 +918,8 @@ export default class VideoPlayer extends React.Component<
|
|
|
918
918
|
const playerContainerStyles = isApplePlatform()
|
|
919
919
|
? styles.playerContainerBlack
|
|
920
920
|
: isTV() && isAudioItem
|
|
921
|
-
|
|
922
|
-
|
|
921
|
+
? styles.playerContainerTransparent
|
|
922
|
+
: styles.playerContainerBlack;
|
|
923
923
|
|
|
924
924
|
const isInline = () => {
|
|
925
925
|
if (isTV()) {
|