Release v0.4.0: Rewrite Plyr.js component with useRef #104

Merged
lamacchinadesiderante merged 1 commits from v0.4.0/complete-plyrjs-integration into develop 2024-05-26 10:38:48 +00:00
1 changed files with 16 additions and 4 deletions

View File

@ -2,6 +2,8 @@
import React from 'react'; import React from 'react';
import { usePlyr } from 'plyr-react';
import style from './PlyrJS.module.scss' import style from './PlyrJS.module.scss'
import { VideoData } from '@/meta/data'; import { VideoData } from '@/meta/data';
@ -16,19 +18,28 @@ interface Props {
const PlyrJS: React.FC<Props> = (props) => { const PlyrJS: React.FC<Props> = (props) => {
const PlyrComponent = React.useMemo(() => { const PlyrComponent = React.useMemo(() => {
return dynamic(() => import("plyr-react"), { ssr: false }); return dynamic(() => import("plyr-react").then(() => {
return React.forwardRef((props, ref) => {
//@ts-ignore
const { source, options = null, ...rest } = props
//@ts-ignore
const raptorRef = usePlyr(ref, {
source,
options,
})
return <video ref={raptorRef} className="plyr-react plyr" {...rest} />
})
}), { ssr: false });
}, []); }, []);
// const Plyr = dynamic(() => import("plyr-react"), { ssr: false });
const { data } = props; const { data } = props;
const plyrProps = { const plyrProps = {
source: { type: 'video', sources: data.srcSet }, // https://github.com/sampotts/plyr#the-source-setter source: { type: 'video', sources: data.srcSet }, // https://github.com/sampotts/plyr#the-source-setter
options: { options: {
controls: [ controls: [
'play-large',
'play', // Play/pause playback 'play', // Play/pause playback
'progress', // The progress bar and scrubber for playback and buffering 'progress', // The progress bar and scrubber for playback and buffering
'current-time', // The current time of playback 'current-time', // The current time of playback
@ -48,6 +59,7 @@ const PlyrJS: React.FC<Props> = (props) => {
<PlyrComponent {...plyrProps} /> <PlyrComponent {...plyrProps} />
</div> </div>
); );
}; };
export default PlyrJS; export default PlyrJS;