Skip to content

Commit c8874ff

Browse files
authored
feat: add autoplay for youtube when fullscreen modals is open (#651)
1 parent 508e99e commit c8874ff

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/components/FullscreenMedia/FullscreenMedia.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import './FullscreenMedia.scss';
1111

1212
export type ChildMediaRenderProps = Pick<
1313
MediaAllProps,
14-
'fullscreen' | 'imageClassName' | 'videoClassName' | 'youtubeClassName' | 'className'
14+
| 'fullscreen'
15+
| 'imageClassName'
16+
| 'videoClassName'
17+
| 'youtubeClassName'
18+
| 'className'
19+
| 'previewImg'
20+
| 'autoplay'
1521
>;
1622

1723
export interface FullscreenMediaProps {
@@ -78,6 +84,8 @@ const FullscreenMedia = ({children, showFullscreenIcon = true}: FullscreenMediaP
7884
videoClassName: getMediaClass('video'),
7985
youtubeClassName: getMediaClass('youtube'),
8086
fullscreen: true,
87+
previewImg: undefined,
88+
autoplay: true,
8189
})}
8290
</div>
8391
</Modal>

src/components/Media/Media.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const b = block('Media');
1616
export interface MediaAllProps extends MediaProps, VideoAdditionProps, ImageAdditionProps, QAProps {
1717
className?: string;
1818
youtubeClassName?: string;
19+
autoplay?: boolean;
1920
}
2021

2122
export const Media = (props: MediaAllProps) => {
@@ -41,6 +42,7 @@ export const Media = (props: MediaAllProps) => {
4142
customBarControlsClassName,
4243
qa,
4344
ratio,
45+
autoplay,
4446
} = props;
4547

4648
const [hasVideoFallback, setHasVideoFallback] = useState(false);
@@ -101,6 +103,7 @@ export const Media = (props: MediaAllProps) => {
101103
height={height}
102104
fullscreen={fullscreen}
103105
analyticsEvents={analyticsEvents}
106+
autoplay={autoplay}
104107
/>
105108
);
106109
}
@@ -132,6 +135,7 @@ export const Media = (props: MediaAllProps) => {
132135
customBarControlsClassName,
133136
ratio,
134137
youtubeClassName,
138+
autoplay,
135139
]);
136140

137141
return (

src/components/VideoBlock/VideoBlock.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface VideoBlockProps extends AnalyticsEventsBase {
5959
playButton?: React.ReactNode;
6060
height?: number;
6161
fullscreen?: boolean;
62+
autoplay?: boolean;
6263
}
6364

6465
const VideoBlock = (props: VideoBlockProps) => {
@@ -73,6 +74,7 @@ const VideoBlock = (props: VideoBlockProps) => {
7374
height,
7475
fullscreen,
7576
analyticsEvents,
77+
autoplay,
7678
} = props;
7779
const handleAnalytics = useAnalytics(DefaultEventNames.VideoPreview);
7880

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

122124
if (!previewImg) {
123-
iframe.src = `${src}?${getPageSearchParams(attributes || {})}`;
125+
iframe.src = `${src}?${getPageSearchParams({
126+
...(attributes || {}),
127+
...(autoplay ? AUTOPLAY_ATTRIBUTES : {}),
128+
})}`;
124129
}
125130

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

138143
useEffect(() => {
139144
setHidePreview(false);

0 commit comments

Comments
 (0)