0

I'm using react function component and plyr-react version 3.2.1.

getting error ref.current.plyr.on is not a function

In 3.1.0 and below version it's working fine

Stackblitz Link - https://stackblitz.com/edit/react-vv9haf

CODE

const PlayerView = () => {
const ref = useRef();
 useEffect(() => {
  ref.current.plyr.on("ended", (event) => {
  console.log("ended-event");
 })
}, [])

 return (
 <Plyr
  id="player"
  options={{ ...options, controls }}
  source={src}
  ref={ref}
 />
);

1 Answers1

0

Please try it

ref?.current?.plyr?.on
Vida Hedayati
  • 328
  • 1
  • 7
  • Thanks for your response, I have tried it. Not worked. Initially the reference gives {source: null}. Added my sample code, Please check this link - https://stackblitz.com/edit/react-vv9haf – Ajith kumar Mar 01 '22 at 17:17
  • ok,I'm trying to suggest another way```ref?.current?.plyr&&ref.current.plyr.on("ended", (event) => { console.log("ended-event")``` – Vida Hedayati Mar 01 '22 at 17:25
  • I have tried your suggestion not worked, below code also not worked if(ref?.current?.plyr && ref.current.plyr.on) { ref.current.plyr.on("ended", (event) => { console.log("ended-event")}) } – Ajith kumar Mar 01 '22 at 18:02
  • Plyr instance doesn't have native methods: https://github.com/chintan9/plyr-react/issues/443 – uruapanmexicansong Aug 17 '22 at 04:57