In next.js app I fetch video urls successfully and want to render them in my app but getting this error: "Uncaught (in promise) DOMException: The element has no supported sources"
I set a video element
<video
loop
onClick={onVideoPress}
ref={videoRef}
src={url}
style={{ objectFit: "cover" }}
/>
this is ref:
const videoRef = useRef(null);
this is the click handler:
const onVideoPress = () => {
if (playing) {
videoRef.current.pause();
setPlaying(false);
} else {
videoRef.current.play();
setPlaying(true);
}
};
this is the source error that chrome tools show:
I wrapped
videoRef.current.play();
withtry/catch
but i got same error:I tried this:
if (videoRef.current !== null) { videoRef.current .play() .then(() => { setPlaying(true); }) .catch((e) => { console.error("eror in play video", e); }); }
and add crossorigin="anonymous"
on video element but still have the same issue
When I click on the video component, videoRef.current
changes to: