Merge pull request 'Release v0.4.0: Rewrite Plyr.js component with useRef' (#104) from v0.4.0/complete-plyrjs-integration into develop

Reviewed-on: #104
This commit is contained in:
lamacchinadesiderante 2024-05-26 10:38:47 +00:00
commit e9365ca27d
1 changed files with 16 additions and 4 deletions

View File

@ -2,6 +2,8 @@
import React from 'react';
import { usePlyr } from 'plyr-react';
import style from './PlyrJS.module.scss'
import { VideoData } from '@/meta/data';
@ -16,19 +18,28 @@ interface Props {
const PlyrJS: React.FC<Props> = (props) => {
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 plyrProps = {
source: { type: 'video', sources: data.srcSet }, // https://github.com/sampotts/plyr#the-source-setter
options: {
controls: [
'play-large',
'play', // Play/pause playback
'progress', // The progress bar and scrubber for playback and buffering
'current-time', // The current time of playback
@ -48,6 +59,7 @@ const PlyrJS: React.FC<Props> = (props) => {
<PlyrComponent {...plyrProps} />
</div>
);
};
export default PlyrJS;