@applicaster/quick-brick-player 16.0.0-alpha.4065452341 → 16.0.0-alpha.4155601029
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 +1 -1
- package/src/Player/AudioLayer/PlaylistNavigationController.ts +354 -0
- package/src/Player/AudioLayer/SleepTimerManager.ts +1 -1
- package/src/Player/AudioLayer/SpeedManager.ts +1 -1
- package/src/Player/AudioLayer/__tests__/PlaylistNavigationController.test.ts +528 -0
- package/src/Player/AudioLayer/__tests__/usePlaylistNavigation.test.ts +153 -1
- package/src/Player/AudioLayer/usePlaylistNavigation.ts +105 -91
- package/src/Player/index.tsx +31 -1
- package/src/logger.ts +3 -5
|
@@ -2,19 +2,44 @@ import * as React from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
4
4
|
import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
retrievePlayPreviousFeedUrl,
|
|
9
|
-
} from "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/utils";
|
|
10
|
-
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
5
|
+
import { PlayerNativeCommandTypes } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/playerNativeCommand";
|
|
6
|
+
import { RemoteCommand } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/const";
|
|
7
|
+
import { PlaylistNavigationController } from "./PlaylistNavigationController";
|
|
11
8
|
|
|
12
|
-
const
|
|
13
|
-
subsystem: "Player",
|
|
14
|
-
category: "usePlaylistNavigation",
|
|
15
|
-
});
|
|
9
|
+
const REMOTE_COMMANDS_LISTENER_ID = "playlist-navigation-remote-commands";
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Buttons native should expose on the lock screen / Control Center / CarPlay.
|
|
13
|
+
* Native enables exactly these and disables the rest. A track button takes its
|
|
14
|
+
* slot over the skip one, since the system shows only one of them per side.
|
|
15
|
+
* Without a next item next is left out, so the system shows it disabled.
|
|
16
|
+
*/
|
|
17
|
+
export const getTransportControls = ({
|
|
18
|
+
hasNext,
|
|
19
|
+
hasPrevious,
|
|
20
|
+
isLive,
|
|
21
|
+
}: {
|
|
22
|
+
hasNext: boolean;
|
|
23
|
+
hasPrevious: boolean;
|
|
24
|
+
isLive: boolean;
|
|
25
|
+
}): RemoteCommand[] => {
|
|
26
|
+
const commands = [
|
|
27
|
+
RemoteCommand.Play,
|
|
28
|
+
isLive ? RemoteCommand.Stop : RemoteCommand.Pause,
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
if (hasPrevious) {
|
|
32
|
+
commands.push(RemoteCommand.PreviousTrack);
|
|
33
|
+
} else if (!isLive) {
|
|
34
|
+
commands.push(RemoteCommand.SkipBackward);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (hasNext) {
|
|
38
|
+
commands.push(RemoteCommand.NextTrack);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return commands;
|
|
42
|
+
};
|
|
18
43
|
|
|
19
44
|
export type PlaylistNavigation = {
|
|
20
45
|
hasNext: boolean;
|
|
@@ -24,8 +49,8 @@ export type PlaylistNavigation = {
|
|
|
24
49
|
};
|
|
25
50
|
|
|
26
51
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
52
|
+
* Thin UI binding hook that subscribes to PlaylistNavigationController's
|
|
53
|
+
* RxJS streams and exposes hasNext, hasPrevious, goNext, and goPrevious.
|
|
29
54
|
*/
|
|
30
55
|
export const usePlaylistNavigation = (
|
|
31
56
|
entry: ZappEntry,
|
|
@@ -36,98 +61,87 @@ export const usePlaylistNavigation = (
|
|
|
36
61
|
// seeking would miss the receiver while casting.
|
|
37
62
|
const player = usePlayer();
|
|
38
63
|
|
|
39
|
-
const [
|
|
64
|
+
const [controller] = React.useState(
|
|
65
|
+
() =>
|
|
66
|
+
new PlaylistNavigationController({
|
|
67
|
+
entry,
|
|
68
|
+
player,
|
|
69
|
+
navigator,
|
|
70
|
+
playerState,
|
|
71
|
+
})
|
|
72
|
+
);
|
|
40
73
|
|
|
41
|
-
React.
|
|
42
|
-
|
|
74
|
+
const [hasNext, setHasNext] = React.useState(() =>
|
|
75
|
+
controller.hasNext$.getValue()
|
|
76
|
+
);
|
|
43
77
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
setNextUrl(url ?? null);
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
.catch((error) => {
|
|
51
|
-
log_error(
|
|
52
|
-
"usePlaylistNavigation: could not resolve the next feed url",
|
|
53
|
-
{ error }
|
|
54
|
-
);
|
|
78
|
+
const [hasPrevious, setHasPrevious] = React.useState(() =>
|
|
79
|
+
controller.hasPrevious$.getValue()
|
|
80
|
+
);
|
|
55
81
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
controller.updateContext({ player, navigator, entry, playerState });
|
|
84
|
+
}, [controller, player, navigator, entry, playerState]);
|
|
85
|
+
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
const subNext = controller.hasNext$.subscribe(setHasNext);
|
|
88
|
+
const subPrev = controller.hasPrevious$.subscribe(setHasPrevious);
|
|
60
89
|
|
|
61
90
|
return () => {
|
|
62
|
-
|
|
91
|
+
subNext.unsubscribe();
|
|
92
|
+
subPrev.unsubscribe();
|
|
93
|
+
controller.destroy();
|
|
63
94
|
};
|
|
64
|
-
}, [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const target = await loadFeedEntry(feedUrl, entry);
|
|
85
|
-
|
|
86
|
-
log_info(`navigateTo: playing "${target.title}", id: ${target.id}`, {
|
|
87
|
-
feedUrl,
|
|
88
|
-
targetId: target.id,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
navigator.replaceTop(target);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
log_error("navigateTo: could not play the neighbouring entry", {
|
|
94
|
-
error,
|
|
95
|
-
feedUrl,
|
|
96
|
-
});
|
|
97
|
-
} finally {
|
|
98
|
-
// Released on failure too, so one bad request cannot latch the control.
|
|
99
|
-
isNavigatingRef.current = false;
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
[entry, navigator]
|
|
95
|
+
}, [controller]);
|
|
96
|
+
|
|
97
|
+
// Lock screen / Control Center / CarPlay next & previous go through the same
|
|
98
|
+
// controller as the on-screen buttons, so JS stays the single source of truth.
|
|
99
|
+
React.useEffect(
|
|
100
|
+
() =>
|
|
101
|
+
player?.addListener?.({
|
|
102
|
+
id: REMOTE_COMMANDS_LISTENER_ID,
|
|
103
|
+
listener: {
|
|
104
|
+
onRemoteCommand: ({ id }) => {
|
|
105
|
+
if (id === RemoteCommand.NextTrack) {
|
|
106
|
+
controller.goNext();
|
|
107
|
+
} else if (id === RemoteCommand.PreviousTrack) {
|
|
108
|
+
controller.goPrevious();
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
[player, controller]
|
|
103
114
|
);
|
|
104
115
|
|
|
105
|
-
const
|
|
106
|
-
if (!nextUrl) return;
|
|
107
|
-
|
|
108
|
-
await navigateTo(nextUrl);
|
|
109
|
-
}, [nextUrl, navigateTo]);
|
|
116
|
+
const isLive = Boolean(playerState?.isLive);
|
|
110
117
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
// Full snapshot: native renders exactly this and drops the rest. Each key is
|
|
119
|
+
// one kind of buttons, so they stay separate lists rather than one flat list.
|
|
120
|
+
React.useEffect(() => {
|
|
121
|
+
const controls = {
|
|
122
|
+
transport: getTransportControls({ hasNext, hasPrevious, isLive }),
|
|
123
|
+
// TODO: other button kinds go in as their own keys next to `transport`,
|
|
124
|
+
// e.g. custom / native-drawn buttons ("play next", CarPlay / Android Auto
|
|
125
|
+
// row buttons). Add a composer on Player once more than this hook fills it.
|
|
126
|
+
// actions: [],
|
|
127
|
+
};
|
|
119
128
|
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
player?.command?.(PlayerNativeCommandTypes.setPlayerControls, controls);
|
|
130
|
+
}, [player, hasNext, hasPrevious, isLive]);
|
|
122
131
|
|
|
123
|
-
|
|
132
|
+
const goNext = React.useCallback(
|
|
133
|
+
async () => controller.goNext(),
|
|
134
|
+
[controller]
|
|
135
|
+
);
|
|
124
136
|
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
const goPrevious = React.useCallback(
|
|
138
|
+
async () => controller.goPrevious(),
|
|
139
|
+
[controller]
|
|
140
|
+
);
|
|
127
141
|
|
|
128
142
|
return {
|
|
129
|
-
hasNext
|
|
130
|
-
hasPrevious
|
|
143
|
+
hasNext,
|
|
144
|
+
hasPrevious,
|
|
131
145
|
goNext,
|
|
132
146
|
goPrevious,
|
|
133
147
|
};
|
package/src/Player/index.tsx
CHANGED
|
@@ -398,6 +398,22 @@ export default class VideoPlayer extends React.Component<
|
|
|
398
398
|
RNPlayerManager?.[this.playerPluginId]?.stopBackgroundPlayback?.();
|
|
399
399
|
};
|
|
400
400
|
|
|
401
|
+
command = (command: string, userInfo?: Record<string, any>) => {
|
|
402
|
+
if (
|
|
403
|
+
this.isReactNativeMethodsSupported() &&
|
|
404
|
+
RNPlayerManager?.[this.playerPluginId]?.command &&
|
|
405
|
+
this._root
|
|
406
|
+
) {
|
|
407
|
+
const node = findNodeHandle(this._root);
|
|
408
|
+
|
|
409
|
+
if (!node) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
RNPlayerManager?.[this.playerPluginId]?.command(node, command, userInfo);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
401
417
|
forward = (seekTime = SEEK_TIME) => {
|
|
402
418
|
const currentTime = this.state.currentTime;
|
|
403
419
|
|
|
@@ -535,6 +551,10 @@ export default class VideoPlayer extends React.Component<
|
|
|
535
551
|
return this.props?.listener?.onError(newError);
|
|
536
552
|
};
|
|
537
553
|
|
|
554
|
+
onRemoteCommand = ({ nativeEvent = null }) => {
|
|
555
|
+
this.props?.listener?.onRemoteCommand?.(nativeEvent);
|
|
556
|
+
};
|
|
557
|
+
|
|
538
558
|
onPlayerPause = ({ nativeEvent = null }) => {
|
|
539
559
|
this.setState({ paused: true });
|
|
540
560
|
this.props?.listener?.onPlayerPause(nativeEvent);
|
|
@@ -544,7 +564,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
544
564
|
const { isAd, resume } = this.state;
|
|
545
565
|
const isNotAnAd = !isAd;
|
|
546
566
|
this.setState({ paused: false });
|
|
547
|
-
this.props?.listener?.onPlayerResume?.(
|
|
567
|
+
this.props?.listener?.onPlayerResume?.(nativeEvent);
|
|
548
568
|
|
|
549
569
|
if (isNotAnAd && !resume) {
|
|
550
570
|
this.setState({ resume: true });
|
|
@@ -1069,6 +1089,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
1069
1089
|
onPlayerResume: this.onPlayerResume,
|
|
1070
1090
|
onPlayerSeekComplete: this.onPlayerSeekComplete,
|
|
1071
1091
|
onPlayerSeekStart: this.onPlayerSeekStart,
|
|
1092
|
+
onRemoteCommand: this.onRemoteCommand,
|
|
1072
1093
|
};
|
|
1073
1094
|
|
|
1074
1095
|
const lifecycleEvents = {
|
|
@@ -1306,10 +1327,16 @@ export default class VideoPlayer extends React.Component<
|
|
|
1306
1327
|
controlsAlwaysVisible={castAction?.state?.connected}
|
|
1307
1328
|
playNextData={this.getPlayNextData()}
|
|
1308
1329
|
needToShowDefaultControls={needToShowDefaultControls}
|
|
1330
|
+
vertical={this.isVerticalPlayer()}
|
|
1309
1331
|
/>
|
|
1310
1332
|
) : null;
|
|
1311
1333
|
};
|
|
1312
1334
|
|
|
1335
|
+
// Single source for the vertical player flag: used by the player wrapper and the transport controls
|
|
1336
|
+
isVerticalPlayer = (): boolean => {
|
|
1337
|
+
return this.getPluginConfiguration()?.vertical_video_player || false;
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1313
1340
|
// Helper method for inline TV check
|
|
1314
1341
|
isInlineTV = () => {
|
|
1315
1342
|
const screenData = getTargetScreenDataFromEntry(this.props.playableItem);
|
|
@@ -1340,6 +1367,8 @@ export default class VideoPlayer extends React.Component<
|
|
|
1340
1367
|
const isFullScreenAudioPlayer =
|
|
1341
1368
|
pluginConfiguration?.full_screen_audio_player || false;
|
|
1342
1369
|
|
|
1370
|
+
const vertical = this.isVerticalPlayer();
|
|
1371
|
+
|
|
1343
1372
|
const sharedWrapperViewProps = {
|
|
1344
1373
|
style,
|
|
1345
1374
|
entry,
|
|
@@ -1347,6 +1376,7 @@ export default class VideoPlayer extends React.Component<
|
|
|
1347
1376
|
docked,
|
|
1348
1377
|
isModal,
|
|
1349
1378
|
pip: piped,
|
|
1379
|
+
vertical,
|
|
1350
1380
|
layoutState: {
|
|
1351
1381
|
inline,
|
|
1352
1382
|
docked,
|
package/src/logger.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
export const Subsystem = "plugins/zapp-react-native-default-player";
|
|
3
|
+
export const Subsystem = "player";
|
|
6
4
|
|
|
7
5
|
export const Categories = {
|
|
8
6
|
PLAYER: "player",
|
|
@@ -19,7 +17,7 @@ export function createLogger({ category = "", subsystem }) {
|
|
|
19
17
|
return null;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
const logger =
|
|
20
|
+
const logger = subsystemLogger(Subsystem, category);
|
|
23
21
|
loggers[subsystem] = logger;
|
|
24
22
|
|
|
25
23
|
return logger;
|