Skip to content

Commit

Permalink
feat: add autoplay for youtube when fullscreen modals is open (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeksandla authored Oct 20, 2023
1 parent 508e99e commit c8874ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/FullscreenMedia/FullscreenMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import './FullscreenMedia.scss';

export type ChildMediaRenderProps = Pick<
MediaAllProps,
'fullscreen' | 'imageClassName' | 'videoClassName' | 'youtubeClassName' | 'className'
| 'fullscreen'
| 'imageClassName'
| 'videoClassName'
| 'youtubeClassName'
| 'className'
| 'previewImg'
| 'autoplay'
>;

export interface FullscreenMediaProps {
Expand Down Expand Up @@ -78,6 +84,8 @@ const FullscreenMedia = ({children, showFullscreenIcon = true}: FullscreenMediaP
videoClassName: getMediaClass('video'),
youtubeClassName: getMediaClass('youtube'),
fullscreen: true,
previewImg: undefined,
autoplay: true,
})}
</div>
</Modal>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Media/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const b = block('Media');
export interface MediaAllProps extends MediaProps, VideoAdditionProps, ImageAdditionProps, QAProps {
className?: string;
youtubeClassName?: string;
autoplay?: boolean;
}

export const Media = (props: MediaAllProps) => {
Expand All @@ -41,6 +42,7 @@ export const Media = (props: MediaAllProps) => {
customBarControlsClassName,
qa,
ratio,
autoplay,
} = props;

const [hasVideoFallback, setHasVideoFallback] = useState(false);
Expand Down Expand Up @@ -101,6 +103,7 @@ export const Media = (props: MediaAllProps) => {
height={height}
fullscreen={fullscreen}
analyticsEvents={analyticsEvents}
autoplay={autoplay}
/>
);
}
Expand Down Expand Up @@ -132,6 +135,7 @@ export const Media = (props: MediaAllProps) => {
customBarControlsClassName,
ratio,
youtubeClassName,
autoplay,
]);

return (
Expand Down
9 changes: 7 additions & 2 deletions src/components/VideoBlock/VideoBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface VideoBlockProps extends AnalyticsEventsBase {
playButton?: React.ReactNode;
height?: number;
fullscreen?: boolean;
autoplay?: boolean;
}

const VideoBlock = (props: VideoBlockProps) => {
Expand All @@ -73,6 +74,7 @@ const VideoBlock = (props: VideoBlockProps) => {
height,
fullscreen,
analyticsEvents,
autoplay,
} = props;
const handleAnalytics = useAnalytics(DefaultEventNames.VideoPreview);

Expand Down Expand Up @@ -120,7 +122,10 @@ const VideoBlock = (props: VideoBlockProps) => {
iframe.id = fullId;

if (!previewImg) {
iframe.src = `${src}?${getPageSearchParams(attributes || {})}`;
iframe.src = `${src}?${getPageSearchParams({
...(attributes || {}),
...(autoplay ? AUTOPLAY_ATTRIBUTES : {}),
})}`;
}

iframe.width = '100%';
Expand All @@ -133,7 +138,7 @@ const VideoBlock = (props: VideoBlockProps) => {
ref.current.appendChild(iframe);
iframeRef.current = iframe;
}
}, [stream, record, norender, src, fullId, attributes, iframeRef, previewImg]);
}, [stream, record, norender, src, fullId, attributes, iframeRef, previewImg, autoplay]);

useEffect(() => {
setHidePreview(false);
Expand Down

0 comments on commit c8874ff

Please sign in to comment.