@applicaster/quick-brick-player 13.0.0-rc.98 → 13.0.0

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.
Files changed (39) hide show
  1. package/package.json +6 -7
  2. package/src/Player/AudioLayer/AudioDescription.tsx +109 -68
  3. package/src/Player/AudioLayer/AudioPlayerWrapper.tsx +81 -189
  4. package/src/Player/AudioLayer/Layout/Controls/VerticalGutter.tsx +23 -5
  5. package/src/Player/AudioLayer/Layout/Controls/index.tsx +46 -60
  6. package/src/Player/AudioLayer/Layout/Controls/utils.ts +5 -13
  7. package/src/Player/AudioLayer/Layout/Debug/index.tsx +55 -0
  8. package/src/Player/AudioLayer/Layout/DockedControls/index.tsx +38 -19
  9. package/src/Player/AudioLayer/Layout/MobileLayout.tsx +35 -25
  10. package/src/Player/AudioLayer/Layout/PlayerImage/AnimatedImage.tsx +39 -40
  11. package/src/Player/AudioLayer/Layout/PlayerImage/FlexImage.tsx +6 -22
  12. package/src/Player/AudioLayer/Layout/PlayerImage/hooks/index.ts +1 -0
  13. package/src/Player/AudioLayer/Layout/PlayerImage/hooks/useChangePlayerState.ts +99 -0
  14. package/src/Player/AudioLayer/Layout/PlayerImage/index.tsx +37 -20
  15. package/src/Player/AudioLayer/Layout/PlayerImage/styles.ts +19 -0
  16. package/src/Player/AudioLayer/Layout/TabletLandscapeLayout.tsx +101 -103
  17. package/src/Player/AudioLayer/Layout/TabletPortraitLayout.tsx +5 -14
  18. package/src/Player/AudioLayer/Layout/TransportInfo/index.tsx +39 -13
  19. package/src/Player/AudioLayer/Layout/const.ts +6 -0
  20. package/src/Player/AudioLayer/Layout/debug.ts +1 -1
  21. package/src/Player/AudioLayer/Layout/hooks/index.ts +3 -1
  22. package/src/Player/AudioLayer/Layout/hooks/useMobileLayoutImageSize.ts +14 -0
  23. package/src/Player/AudioLayer/Layout/hooks/{useImageSize.ts → useTabletLayoutImageSize.ts} +10 -5
  24. package/src/Player/AudioLayer/Layout/hooks/useTransportInfoHeight.ts +1 -1
  25. package/src/Player/AudioLayer/Layout/utils.ts +7 -0
  26. package/src/Player/AudioLayer/SleepTimerManager.ts +22 -11
  27. package/src/Player/AudioLayer/components/SleepTimerModalHeader/SleepTimerModalHeader.tsx +66 -0
  28. package/src/Player/AudioLayer/components/SleepTimerModalHeader/index.ts +1 -0
  29. package/src/Player/AudioLayer/useSleepTimerModal.ts +109 -0
  30. package/src/Player/Const/sleepTimerOptions.ts +7 -5
  31. package/src/Player/Utils/index.tsx +6 -0
  32. package/src/Player/hooks/useIsCasting.tsx +57 -0
  33. package/src/Player/index.tsx +84 -37
  34. package/src/QuickBrickPlayer.tsx +3 -0
  35. package/src/Player/AudioLayer/LinearGradient/LinearGradientProxy.ts +0 -3
  36. package/src/Player/AudioLayer/LinearGradient/LinearGradientProxy.web.ts +0 -3
  37. package/src/Player/AudioLayer/LinearGradient/index.ts +0 -1
  38. package/src/Player/AudioLayer/MagicBG/index.tsx +0 -155
  39. package/src/utils/utils.ts +0 -25
@@ -4,6 +4,8 @@
4
4
  import React from "react";
5
5
  import * as R from "ramda";
6
6
 
7
+ import { flatten } from "@applicaster/zapp-react-native-utils/utils";
8
+
7
9
  import { findNodeHandle, StyleSheet, View } from "react-native";
8
10
  import TransportControlsMobile from "@applicaster/quick-brick-mobile-transport-controls";
9
11
  import TransportControlsTV from "@applicaster/quick-brick-tv-transport-controls";
@@ -31,7 +33,6 @@ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
31
33
  import { getAllAccessibilityProps } from "@applicaster/zapp-react-native-utils/configurationUtils";
32
34
  import { PlayNextData } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainer";
33
35
  import { getTargetScreenDataFromEntry } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useTargetScreenData";
34
- import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
35
36
  import {
36
37
  AnimationComponent,
37
38
  ComponentAnimationType,
@@ -40,6 +41,10 @@ import { PlayerAnalyticsManager } from "@applicaster/zapp-react-native-utils/ana
40
41
  import { PlayerAnalyticsTrackerI } from "@applicaster/zapp-react-native-utils/analyticsUtils/playerAnalyticsTracker";
41
42
 
42
43
  import { RNPlayerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/nativePlayerManager";
44
+ import {
45
+ isAudioItem as isAudioItemUtil,
46
+ isInlineTV as isInlineTVUtil,
47
+ } from "@applicaster/zapp-react-native-utils/playerUtils";
43
48
 
44
49
  const styles = StyleSheet.create({
45
50
  container: { flex: 1 },
@@ -50,6 +55,7 @@ const styles = StyleSheet.create({
50
55
  position: "absolute",
51
56
  zIndex: 1,
52
57
  },
58
+ audioPlayerSize: { width: "100%", height: "100%" },
53
59
  playerSize: { width: "100%", height: "100%" },
54
60
  });
55
61
 
@@ -58,6 +64,10 @@ const logger = createLogger({
58
64
  subsystem: Subsystem,
59
65
  });
60
66
 
67
+ const isTvOS = isTvOSPlatform();
68
+
69
+ const AUDIO_PLAYER_NATIVE_ID = "audio-player-view";
70
+
61
71
  export default class VideoPlayer extends React.Component<
62
72
  QuickBrickPlayer.PlayerProps,
63
73
  QuickBrickPlayer.NativePlayerState
@@ -74,6 +84,7 @@ export default class VideoPlayer extends React.Component<
74
84
  state: QuickBrickPlayer.NativePlayerState = {
75
85
  audioTrackId: null,
76
86
  textTrackId: null,
87
+ isCasting: this.props.isCasting,
77
88
 
78
89
  // TODO: Can be deleted, on controller logic
79
90
  isAd: false,
@@ -92,6 +103,8 @@ export default class VideoPlayer extends React.Component<
92
103
  // Player state
93
104
  currentTime: 0,
94
105
  duration: 0,
106
+
107
+ nativePlayerIsReady: false,
95
108
  };
96
109
 
97
110
  private _tracker: PlayerAnalyticsTrackerI;
@@ -487,6 +500,9 @@ export default class VideoPlayer extends React.Component<
487
500
 
488
501
  onVideoFullscreenPlayerDidPresent = () => {
489
502
  this.props.listener?.onVideoFullscreenPlayerDidPresent?.();
503
+
504
+ // we have to have a signal that player is ready, in order to show audio_player(for example)
505
+ this.setState({ nativePlayerIsReady: true });
490
506
  };
491
507
 
492
508
  onVideoFullscreenPlayerWillDismiss = () => {
@@ -672,32 +688,57 @@ export default class VideoPlayer extends React.Component<
672
688
  }
673
689
  };
674
690
 
675
- childrenWithPlayNext = () => {
676
- if (!isTvOSPlatform() || !this.getPlayNextData()) {
677
- return this.props.children;
691
+ childrenWithExtensions = () => {
692
+ const { docked, entry, children } = this.props;
693
+
694
+ if (!isTvOS) {
695
+ return children;
678
696
  }
679
697
 
680
- // tvos only
681
- const { docked, entry } = this.props;
682
-
683
- const children = R.pathOr([], "children", this.props);
684
-
685
- return [
686
- ...children,
687
- <PlayNextOverlay
688
- key="play-next-overlay"
689
- item={entry}
690
- playerIsDocked={docked}
691
- pluginConfiguration={this.getPluginConfiguration()}
692
- playerId={this.props.playerId}
693
- playNextData={this.getPlayNextData()}
694
- setNextVideoPreloadThresholdPercentage={
695
- this.props.setNextVideoPreloadThresholdPercentage
696
- }
697
- />,
698
- ];
698
+ const output = [];
699
+
700
+ // audio-player
701
+ if (isAudioItemUtil(entry)) {
702
+ const { nativePlayerIsReady } = this.state;
703
+
704
+ // we have to wait ready status of native player view, before showing audio_player
705
+ if (nativePlayerIsReady) {
706
+ output.push(
707
+ <View nativeID={AUDIO_PLAYER_NATIVE_ID} key={AUDIO_PLAYER_NATIVE_ID}>
708
+ {children}
709
+ </View>
710
+ );
711
+ }
712
+ } else {
713
+ output.push(children);
714
+ }
715
+ // audio-player
716
+
717
+ // play-next
718
+ if (this.getPlayNextData()) {
719
+ output.push(
720
+ <PlayNextOverlay
721
+ key="play-next-overlay"
722
+ item={entry}
723
+ playerIsDocked={docked}
724
+ pluginConfiguration={this.getPluginConfiguration()}
725
+ playerId={this.props.playerId}
726
+ playNextData={this.getPlayNextData()}
727
+ setNextVideoPreloadThresholdPercentage={
728
+ this.props.setNextVideoPreloadThresholdPercentage
729
+ }
730
+ />
731
+ );
732
+ }
733
+ // play-next
734
+
735
+ return flatten(output); // prevent possible case with nested array
699
736
  };
700
737
 
738
+ get supportNativeCast() {
739
+ return this.props.controller.supportNativeCast();
740
+ }
741
+
701
742
  render() {
702
743
  const {
703
744
  docked,
@@ -710,18 +751,13 @@ export default class VideoPlayer extends React.Component<
710
751
  muted,
711
752
  style,
712
753
  castAction,
713
- controller,
714
754
  startComponentsAnimation,
715
755
  } = this.props;
716
756
 
717
- const supportNativeCast = controller.supportNativeCast();
718
-
719
757
  const { audioTrackId, keyEvent, paused, seek, textTrackId, rate } =
720
758
  this.state;
721
759
 
722
- const isAudioItem =
723
- entry?.content?.type?.includes?.("audio") ||
724
- entry?.type?.value?.includes?.("audio");
760
+ const isAudioItem = isAudioItemUtil(entry);
725
761
 
726
762
  const getStyle = (dimensions) => {
727
763
  const generalStyles = isAudioItem ? styles.audio : styles.video;
@@ -765,7 +801,7 @@ export default class VideoPlayer extends React.Component<
765
801
  // TODO: Get screen data more reliable way useCurrentScreenData
766
802
  const screenData = getTargetScreenDataFromEntry(this.props.playableItem);
767
803
 
768
- const isInlineTV = screenData?.ui_components?.length > 0 && isTV();
804
+ const isInlineTV = isInlineTVUtil(screenData);
769
805
 
770
806
  let platformSpecificProps: any = isApplePlatform()
771
807
  ? {
@@ -776,7 +812,7 @@ export default class VideoPlayer extends React.Component<
776
812
  const supportsNativeControls =
777
813
  !!this.props.controller?.supportsNativeControls?.();
778
814
 
779
- const controls = isAppleTV()
815
+ const controls = isTvOS
780
816
  ? (supportsNativeControls && !isInlineTV) || !!this.getPlayNextData()
781
817
  : supportsNativeControls && !this.getPlayNextData();
782
818
 
@@ -823,7 +859,7 @@ export default class VideoPlayer extends React.Component<
823
859
  ),
824
860
  };
825
861
 
826
- if (!isAppleTV()) {
862
+ if (!isTvOS) {
827
863
  // TODO: Move to RN method and remove from props.
828
864
  // Causes tvOS bug: native player passes rate on fast seek,
829
865
  // RN returns it and it breaks playback.
@@ -995,11 +1031,14 @@ export default class VideoPlayer extends React.Component<
995
1031
  const backgroundImageKey =
996
1032
  this.getPluginConfiguration()?.player_preview_image_key;
997
1033
 
1034
+ const shouldRenderNativePlayer =
1035
+ !this.props.isCasting || this.supportNativeCast;
1036
+
998
1037
  const renderMobilePlayer = () => {
999
1038
  return isFullScreenAudioPlayer && isAudioItem ? (
1000
1039
  // Ensure the View remains in the native hierarchy for proper rendering and interaction
1001
1040
  <View collapsable={false} style={containerStyle}>
1002
- {!castAction?.state?.connected || supportNativeCast ? (
1041
+ {shouldRenderNativePlayer ? (
1003
1042
  <this.props.PlayerComponent
1004
1043
  ref={this._assignRoot}
1005
1044
  {...nativeEvents}
@@ -1051,7 +1090,7 @@ export default class VideoPlayer extends React.Component<
1051
1090
  />
1052
1091
  ) : null}
1053
1092
 
1054
- {!castAction?.state?.connected || supportNativeCast ? (
1093
+ {shouldRenderNativePlayer ? (
1055
1094
  <AnimationComponent
1056
1095
  animationType={ComponentAnimationType.player}
1057
1096
  additionalData={{
@@ -1073,7 +1112,7 @@ export default class VideoPlayer extends React.Component<
1073
1112
  pluginConfiguration={this.getPluginConfiguration()}
1074
1113
  controller={this.props.controller}
1075
1114
  >
1076
- {this.childrenWithPlayNext()}
1115
+ {this.props.children}
1077
1116
  </this.props.PlayerComponent>
1078
1117
  </AnimationComponent>
1079
1118
  ) : null}
@@ -1102,6 +1141,14 @@ export default class VideoPlayer extends React.Component<
1102
1141
  const renderTVPlayer = () => {
1103
1142
  return (
1104
1143
  <View style={this.takeParentStyle} testID={"player-view"}>
1144
+ {isAudioItem && (isInlineTV || !isTvOS) ? (
1145
+ <AudioPlayer
1146
+ style={getStyle(styles.audioPlayerSize)}
1147
+ audio_item={entry}
1148
+ plugin_configuration={this.getPluginConfiguration()}
1149
+ />
1150
+ ) : null}
1151
+
1105
1152
  <this.props.PlayerComponent
1106
1153
  ref={this._assignRoot}
1107
1154
  {...nativeEvents}
@@ -1111,11 +1158,11 @@ export default class VideoPlayer extends React.Component<
1111
1158
  pluginConfiguration={this.getPluginConfiguration()}
1112
1159
  controller={this.props.controller}
1113
1160
  >
1114
- {this.childrenWithPlayNext()}
1161
+ {!isInlineTV && this.childrenWithExtensions()}
1115
1162
  </this.props.PlayerComponent>
1116
1163
 
1117
1164
  {renderTransportControls(this.takeParentStyle)}
1118
- {!isTvOSPlatform() && (
1165
+ {!isTvOS && (
1119
1166
  <PlayNextOverlay
1120
1167
  item={entry}
1121
1168
  playerIsDocked={docked}
@@ -5,6 +5,7 @@ import Player from "./Player";
5
5
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
6
6
  import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
7
7
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
8
+ import { useIsCasting } from "./Player/hooks/useIsCasting";
8
9
 
9
10
  const CHROMECAST_IDENTIFIER = "quick-brick-chromecast-action";
10
11
 
@@ -24,6 +25,7 @@ const QuickBrickPlayerComponent = (
24
25
  }, [props.PlayerComponent]);
25
26
 
26
27
  const castAction = useActions(CHROMECAST_IDENTIFIER);
28
+ const isCasting = useIsCasting();
27
29
 
28
30
  const isModal = Boolean(props?.isModal);
29
31
  const isScreenDisabled = !controller?.isFullScreenSupported() || !isModal;
@@ -48,6 +50,7 @@ const QuickBrickPlayerComponent = (
48
50
  {...props}
49
51
  ref={ref}
50
52
  castAction={!props?.disableCastAction && castAction}
53
+ isCasting={isCasting}
51
54
  PlayerComponent={props.PlayerComponent}
52
55
  openPiP={openPiP}
53
56
  closePiP={closePiP}
@@ -1,3 +0,0 @@
1
- import LinearGradient from "react-native-linear-gradient";
2
-
3
- export default LinearGradient;
@@ -1,3 +0,0 @@
1
- const WebLinearGradient = require("react-native-web-linear-gradient").default;
2
-
3
- export default WebLinearGradient;
@@ -1 +0,0 @@
1
- export { default } from "./LinearGradientProxy";
@@ -1,155 +0,0 @@
1
- /* eslint-disable react/prop-types */
2
- import * as React from "react";
3
- import { Animated, StyleSheet, View } from "react-native";
4
- import LinearGradient from "../LinearGradient";
5
- import { getDominantColor, getPalettes } from "../../../utils/utils";
6
- import { useEffect } from "react";
7
-
8
- type MagicBGProps = {
9
- children: React.ReactNode;
10
- image: string;
11
- fallbackUrl?: string;
12
- defaultColor: string;
13
- colors: string[];
14
- };
15
-
16
- const defaultColors = {
17
- overlay: "rgba(0, 0, 0, 0.35)",
18
- defaultGradientStart: "rgba(0, 0, 0, 0.25)",
19
- defaultGradientEnd: "rgba(0, 0, 0, 0)",
20
- };
21
-
22
- const styles = StyleSheet.create({
23
- container: {
24
- flex: 1,
25
- },
26
- fullScreenOverlay: {
27
- ...StyleSheet.absoluteFillObject,
28
- backgroundColor: defaultColors.overlay,
29
- },
30
- gradientOverlay: {
31
- position: "absolute",
32
- bottom: 0,
33
- left: 0,
34
- right: 0,
35
- height: "100%",
36
- },
37
- });
38
-
39
- const fetchPaletteAndDominantColor = async (imageUrl: string) => {
40
- const palette = await getPalettes(imageUrl);
41
-
42
- const colors = palette.map(
43
- (color: { r: number; g: number; b: number }) =>
44
- `rgb(${color.r}, ${color.g}, ${color.b})`
45
- );
46
-
47
- const dominant = await getDominantColor(imageUrl);
48
- const dominantColor = `rgb(${dominant.r}, ${dominant.g}, ${dominant.b})`;
49
-
50
- return { gradientColors: colors.slice(0, 2).reverse(), dominantColor };
51
- };
52
-
53
- export const MagicBG: React.FC<MagicBGProps> = ({
54
- children,
55
- image,
56
- fallbackUrl = "",
57
- colors = [],
58
- defaultColor,
59
- }) => {
60
- const [dominantColor, setDominantColor] =
61
- React.useState<string>(defaultColor);
62
-
63
- const [gradientColors, setGradientColors] = React.useState<string[]>([
64
- defaultColors.defaultGradientStart,
65
- defaultColors.defaultGradientEnd,
66
- ]);
67
-
68
- const [backgroundColorAnim] = React.useState(new Animated.Value(0)); // from 0 to 1
69
- const [gradientOpacityAnim] = React.useState(new Animated.Value(0)); // from 0 to 1
70
-
71
- useEffect(() => {
72
- const animateColors = () => {
73
- Animated.timing(backgroundColorAnim, {
74
- toValue: 1,
75
- duration: 500,
76
- useNativeDriver: false,
77
- }).start();
78
-
79
- Animated.timing(gradientOpacityAnim, {
80
- toValue: 1,
81
- duration: 500,
82
- useNativeDriver: false,
83
- }).start();
84
- };
85
-
86
- const fetchColors = async () => {
87
- if (colors && colors.length > 0) {
88
- setGradientColors(colors.slice(0, 2));
89
- setDominantColor(colors[0]);
90
- animateColors();
91
- } else if (image) {
92
- try {
93
- const { gradientColors, dominantColor } =
94
- await fetchPaletteAndDominantColor(image);
95
-
96
- setGradientColors(gradientColors);
97
- setDominantColor(dominantColor);
98
- animateColors();
99
- } catch (error) {
100
- try {
101
- const { gradientColors, dominantColor } =
102
- await fetchPaletteAndDominantColor(fallbackUrl);
103
-
104
- setGradientColors(gradientColors);
105
- setDominantColor(dominantColor);
106
- animateColors();
107
- } catch {
108
- setGradientColors([
109
- defaultColors.defaultGradientStart,
110
- defaultColors.defaultGradientEnd,
111
- ]);
112
-
113
- setDominantColor(defaultColor);
114
- }
115
- }
116
- } else {
117
- setGradientColors([
118
- defaultColors.defaultGradientStart,
119
- defaultColors.defaultGradientEnd,
120
- ]);
121
-
122
- setDominantColor(defaultColor);
123
- }
124
- };
125
-
126
- fetchColors();
127
- }, []);
128
-
129
- const interpolatedBackgroundColor = backgroundColorAnim.interpolate({
130
- inputRange: [0, 1],
131
- outputRange: ["black", dominantColor],
132
- });
133
-
134
- return (
135
- <Animated.View
136
- style={[
137
- styles.container,
138
- { backgroundColor: interpolatedBackgroundColor },
139
- ]}
140
- >
141
- <View style={styles.fullScreenOverlay} />
142
-
143
- <Animated.View
144
- style={[styles.gradientOverlay, { opacity: gradientOpacityAnim }]}
145
- >
146
- <LinearGradient
147
- colors={gradientColors}
148
- style={StyleSheet.absoluteFill}
149
- />
150
- </Animated.View>
151
-
152
- {children}
153
- </Animated.View>
154
- );
155
- };
@@ -1,25 +0,0 @@
1
- import RNColorThief from "@applicaster/react-native-color-thief";
2
- import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
3
-
4
- const { log_error } = createLogger({
5
- subsystem: "UIComponent",
6
- category: "MagicBackground",
7
- });
8
-
9
- export const getDominantColor = async (imageUrl: string): Promise<any> => {
10
- try {
11
- return await RNColorThief.getColor(imageUrl, 1, false);
12
- } catch (error) {
13
- log_error("Failed to get the dominant color", { error });
14
- throw error;
15
- }
16
- };
17
-
18
- export const getPalettes = async (imageUrl: string): Promise<any> => {
19
- try {
20
- return await RNColorThief.getPalette(imageUrl, 3, 1, true);
21
- } catch (error) {
22
- log_error("Failed to get the palette", { error });
23
- throw error;
24
- }
25
- };