Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/Media/Video/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const Video = (props: VideoAllProps) => {
playButton,
ariaLabel,
customControlsOptions,
contain,
} = video;

return (
Expand All @@ -104,7 +105,9 @@ const Video = (props: VideoAllProps) => {
height={height}
ariaLabel={ariaLabel}
customControlsOptions={customControlsOptions}
ratio={ratio}
ratio={ratio === 'auto' ? undefined : ratio}
autoRatio={ratio === 'auto'}
contain={contain}
/>
);
}, [
Expand Down
9 changes: 9 additions & 0 deletions src/components/ReactPlayer/ReactPlayer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
$block: '.#{$ns}ReactPlayer';

#{$block} {
video {
background-color: var(--pc-color-video-player-bg, $videoPlayerBg);
object-fit: cover;
}

&__wrapper {
position: relative;
// Player ratio: 100 / (1280 / 720)
Expand Down Expand Up @@ -67,6 +72,10 @@ $block: '.#{$ns}ReactPlayer';
}
}

&_contain video {
object-fit: contain;
}

@media only screen and (max-width: map-get($gridBreakpoints, 'sm')) {
&__button_text {
font-size: 20px;
Expand Down
25 changes: 22 additions & 3 deletions src/components/ReactPlayer/ReactPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface ReactPlayerBlockProps
onClickPreview?: () => void;
height?: number;
ratio?: number;
autoRatio?: boolean;
children?: React.ReactNode;
}

Expand Down Expand Up @@ -87,6 +88,8 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
height,
ariaLabel,
ratio,
autoRatio,
contain,
} = props;

const {
Expand All @@ -113,6 +116,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
const [playedPercent, setPlayedPercent] = useState<number>(0);
const [currentHeight, setCurrentHeight] = useState(height);
const [width, setWidth] = useState<number>(0);
const [actualRatio, setActualRatio] = useState<number>();
const [muted, setMuted] = useState<boolean>(mute);
const [started, setStarted] = useState(autoPlay);
const [ended, setEnded] = useState<boolean>(false);
Expand Down Expand Up @@ -202,7 +206,11 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
parseFloat(paddingRight);

setWidth(newWidth);
setCurrentHeight(Math.floor(getHeight(newWidth, ratio)));
setCurrentHeight(
Math.floor(
getHeight(newWidth, ratio ?? (autoRatio ? actualRatio : undefined)),
),
);
}
}, 200);

Expand All @@ -211,7 +219,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
return () => {
window.removeEventListener('resize', updateSize);
};
}, [ratio]);
}, [actualRatio, autoRatio, ratio]);

const playEvents = useMemo(
() => eventsArray?.filter((e: AnalyticsEvent) => e.type === PredefinedEventTypes.Play),
Expand Down Expand Up @@ -317,6 +325,16 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
}
}, [changeMute, controls, customControlsType, ended, isPlaying, muted]);

const onReady = useCallback((player: ReactPlayer) => {
setPlayerRef(player);
const videoElement = player.getInternalPlayer();
const videoWidth = videoElement.videoWidth as number | undefined;
const videoHeight = videoElement.videoHeight as number | undefined;
if (videoWidth && videoHeight) {
setActualRatio(videoHeight / videoWidth);
}
}, []);

const onProgress = useCallback((progress: PlayerPropgress) => {
setPlayedPercent(progress.played);

Expand Down Expand Up @@ -365,6 +383,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
{
wrapper: !currentHeight,
controls,
contain,
},
className,
)}
Expand All @@ -390,7 +409,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
progressInterval={FPS}
onClickPreview={handleClickPreview}
onStart={onStart}
onReady={setPlayerRef}
onReady={onReady}
onPlay={onPlay}
onPause={
autoPlay && customControlsType !== CustomControlsType.WithMuteButton
Expand Down
3 changes: 2 additions & 1 deletion src/models/constructor-items/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export interface MediaVideoProps extends AnalyticsEventsBase {
controls?: MediaVideoControlsType;
customControlsOptions?: CustomControlsOptions;
ariaLabel?: string;
contain?: boolean;
}

// links
Expand Down Expand Up @@ -248,7 +249,7 @@ export type ThemedMediaVideoProps = ThemeSupporting<MediaVideoProps>;
export interface MediaComponentVideoProps extends AnalyticsEventsBase {
video: MediaVideoProps;
height?: number;
ratio?: number;
ratio?: number | 'auto';
previewImg?: string;
}

Expand Down
6 changes: 5 additions & 1 deletion src/schema/validators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ export const VideoProps = {
ariaLabel: {
type: 'string',
},
contain: {
type: 'boolean',
},
},
};

Expand Down Expand Up @@ -624,7 +627,8 @@ export const MediaProps = {
anyOf: [AnalyticsEventSchema, {type: 'array', items: AnalyticsEventSchema}],
},
ratio: {
type: 'number',
type: ['number', 'string'],
pattern: '^auto$',
},
iframe: {
...IframeProps,
Expand Down
1 change: 1 addition & 0 deletions styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ $animationDuration: 300ms;

//colors
$videoPlayButtonGrey: #eff2f8;
$videoPlayerBg: #000;
$secondary: var(--g-color-text-secondary);
$lightSecondary: var(--g-color-text-light-secondary);

Expand Down