Open timomedia opened 10 months ago
Make it client component and use dynamic import
const Plyr = dynamic(() => import("plyr-react"), { ssr: false });
Make it client component and use dynamic import
const Plyr = dynamic(() => import("plyr-react"), { ssr: false });
It really doesn't work. I tried using dynamic but it didn't work. I created a component called Player to use in different pages and using it the way you do doesn't work at all. Below is my original code that tried to use dynamic"use client" import React, { useEffect, useRef } from "react"; import dynamic from "next/dynamic"; import Hls from "hls.js";
const PlyrComponent = dynamic(() => import("plyr-react"), { ssr: false });
export default function Player({ videoUrl, poster }) { const option = { autoplay: false, controls: [ 'rewind', 'play', 'fast-forward', 'progress', 'current-time', 'duration', 'mute', 'volume', 'settings', 'quality', 'fullscreen', ], }; const ref = useRef(null);
useEffect(() => {
const loadVideo = async () => {
if (ref.current && typeof window !== 'undefined') {
const plyr = ref.current.get('plyr');
if (plyr) {
var hls = new Hls();
hls.loadSource(videoUrl);
hls.attachMedia(plyr.media);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
plyr.play();
});
}
}
};
loadVideo();
}, [videoUrl]);
return (
<PlyrComponent
ref={ref}
playsInline
source={{
type: "video",
sources: [{ src: videoUrl, type: 'application/vnd.apple.mpegurl' }],
}}
poster={poster}
options={option}
/>
);
}
I use Plyr on next.js 14 and get the error "document is not defined". Previous versions all worked fine, only when upgrading to next.js 14 did I encounter the above error. Specifically, the error appears as below. Please help me check it
null