Attempt to fix video not autoplaying on Mobile Safari

This commit is contained in:
Lim Chee Aun 2022-12-24 14:15:34 +08:00
parent 42fa30d8f8
commit c4efc26d62

View file

@ -743,30 +743,35 @@ function Media({ media, showOriginal, onClick = () => {} }) {
rgbAverageColor && `rgb(${rgbAverageColor.join(',')})`, rgbAverageColor && `rgb(${rgbAverageColor.join(',')})`,
}} }}
onClick={(e) => { onClick={(e) => {
if (isGIF) { if (showOriginal && isGIF) {
try { try {
videoRef.current?.pause(); if (videoRef.current.paused) {
videoRef.current.play();
} else {
videoRef.current.pause();
}
} catch (e) {} } catch (e) {}
} }
onClick(e); onClick(e);
}} }}
onMouseEnter={() => { onMouseEnter={() => {
if (isGIF) { if (!showOriginal && isGIF) {
try { try {
videoRef.current?.play(); videoRef.current.play();
} catch (e) {} } catch (e) {}
} }
}} }}
onMouseLeave={() => { onMouseLeave={() => {
if (isGIF) { if (!showOriginal && isGIF) {
try { try {
videoRef.current?.pause(); videoRef.current.pause();
} catch (e) {} } catch (e) {}
} }
}} }}
> >
{showOriginal ? ( {showOriginal ? (
<video <video
ref={videoRef}
src={url} src={url}
poster={previewUrl} poster={previewUrl}
width={width} width={width}
@ -777,13 +782,6 @@ function Media({ media, showOriginal, onClick = () => {} }) {
controls={!isGIF} controls={!isGIF}
playsinline playsinline
loop={loopable} loop={loopable}
onClick={() => {
if (isGIF) {
try {
videoRef.current?.play();
} catch (e) {}
}
}}
></video> ></video>
) : isGIF ? ( ) : isGIF ? (
<video <video