onclick on video pause the video

Relates #1843
pull/1839/head
audric 4 years ago
parent f84fa2492f
commit b83067d0ee

@ -196,6 +196,7 @@ const Icon = ({
/> />
); );
// tslint:disable-next-line: max-func-body-length
export const LightboxObject = ({ export const LightboxObject = ({
objectURL, objectURL,
contentType, contentType,
@ -216,37 +217,12 @@ export const LightboxObject = ({
return false; return false;
}, []); }, []);
const playVideo = () => {
if (!videoRef) {
return;
}
const { current } = videoRef;
if (!current) {
return;
}
if (current.paused) {
void current.play();
} else {
current.pause();
}
};
const pauseVideo = () => {
if (!videoRef) {
return;
}
const { current } = videoRef;
if (current) {
current.pause();
}
};
// auto play video on showing a video attachment // auto play video on showing a video attachment
useUnmount(() => { useUnmount(() => {
pauseVideo(); if (!videoRef?.current) {
return;
}
videoRef.current.pause.pause();
}); });
if (isImageTypeSupported) { if (isImageTypeSupported) {
@ -263,13 +239,15 @@ export const LightboxObject = ({
const isVideoTypeSupported = GoogleChrome.isVideoTypeSupported(contentType); const isVideoTypeSupported = GoogleChrome.isVideoTypeSupported(contentType);
if (isVideoTypeSupported) { if (isVideoTypeSupported) {
if (urlToLoad) { if (urlToLoad) {
playVideo(); if (videoRef?.current.paused) {
void videoRef.current.play();
} }
}
return ( return (
<video <video
role="button" role="button"
ref={videoRef} ref={videoRef}
onClick={playVideo}
controls={true} controls={true}
style={styles.object as any} style={styles.object as any}
key={urlToLoad} key={urlToLoad}

Loading…
Cancel
Save