Skip to content

Commit

Permalink
Fix video player aspect ratio (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot authored Jul 27, 2023
1 parent fd70b29 commit 49b8442
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
15 changes: 15 additions & 0 deletions met-web/src/components/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Palette } from 'styles/Theme';
import LoadingButton from '@mui/lab/LoadingButton';
import { MET_Header_Font_Family, MET_Header_Font_Weight } from '../../styles/constants';
import { When } from 'react-if';
import ReactPlayer from 'react-player';

export const MetTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} />
Expand Down Expand Up @@ -454,3 +455,17 @@ export const MetDisclaimer = ({ children }: { children: React.ReactNode }) => {
</Box>
);
};

export const AspectRatioContainer = styled('div')({
position: 'relative',
width: '100%',
paddingTop: '56.25%' /* 16:9 aspect ratio (height / width * 100) */,
});

export const ReactPlayerWrapper = styled(ReactPlayer)({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useEffect, useState } from 'react';
import { MetPaper, MetHeader2, MetParagraph } from 'components/common';
import { MetPaper, MetHeader2, MetParagraph, AspectRatioContainer, ReactPlayerWrapper } from 'components/common';
import { Grid, Skeleton, Divider } from '@mui/material';
import { Widget } from 'models/widget';
import { useAppDispatch } from 'hooks';
import { openNotification } from 'services/notificationService/notificationSlice';
import { VideoWidget } from 'models/videoWidget';
import { fetchVideoWidgets } from 'services/widgetService/VideoService';
import ReactPlayer from 'react-player/lazy';

interface VideoWidgetProps {
widget: Widget;
Expand Down Expand Up @@ -69,29 +68,36 @@ const VideoWidgetView = ({ widget }: VideoWidgetProps) => {
}

return (
<>
<MetPaper elevation={1} sx={{ paddingTop: '0.5em', padding: '1em' }}>
<Grid container justifyContent={{ xs: 'center' }} alignItems="center" rowSpacing={2}>
<Grid
item
container
justifyContent={{ xs: 'center', md: 'flex-start' }}
flexDirection={'column'}
xs={12}
paddingBottom={0}
>
<MetHeader2 bold>Video</MetHeader2>
<Divider sx={{ borderWidth: 1, marginTop: 0.5 }} />
</Grid>
<Grid item xs={12}>
<MetParagraph>{videoWidget.description}</MetParagraph>
</Grid>
<Grid item xs={12}>
<ReactPlayer url={videoWidget.video_url} controls width="100%" config={playerConfig} />
</Grid>
<MetPaper elevation={1} sx={{ paddingTop: '0.5em', padding: '1em' }}>
<Grid container justifyContent={{ xs: 'center' }} alignItems="center" rowSpacing={2}>
<Grid
item
container
justifyContent={{ xs: 'center', md: 'flex-start' }}
flexDirection={'column'}
xs={12}
paddingBottom={0}
>
<MetHeader2 bold>Video</MetHeader2>
<Divider sx={{ borderWidth: 1, marginTop: 0.5 }} />
</Grid>
</MetPaper>
</>
<Grid item xs={12}>
<MetParagraph>{videoWidget.description}</MetParagraph>
</Grid>
<Grid item xs={12}>
<AspectRatioContainer>
<ReactPlayerWrapper
url={videoWidget.video_url}
controls
width="100%"
height={'100%'}
config={playerConfig}
light
/>
</AspectRatioContainer>
</Grid>
</Grid>
</MetPaper>
);
};

Expand Down

0 comments on commit 49b8442

Please sign in to comment.