matvp91 / shaka-player-react

A simple React component wrapper for shaka-player
MIT License
110 stars 34 forks source link

Cannot read properties of null (reading 'configure') #26

Closed zalazarc20 closed 1 year ago

zalazarc20 commented 1 year ago

I am using mpd link which need drm clearkey, when i use

player.configure({
    drm: {
      clearKeys: {"123":"456"} // example clearkey
    }
  })

I get this error Cannot read properties of null (reading 'configure') Is it not possible to use drm with this component? I'll keep investigating because I'm also getting the same error from my player.load, but if someone has already encountered this error, your help would be useful

Sorry for my bad English and thanks for reading my problem.

zalazarc20 commented 1 year ago

I am using mpd link which need drm clearkey, when i use

player.configure({
    drm: {
      clearKeys: {"123":"456"} // example clearkey
    }
  })

I get this error Cannot read properties of null (reading 'configure') Is it not possible to use drm with this component? I'll keep investigating because I'm also getting the same error from my player.load, but if someone has already encountered this error, your help would be useful

Sorry for my bad English and thanks for reading my problem.

I just found the solution by reading the base code.

my solution was the following

const Player = ({ link, ck = null }) => {
  const controllerRef = useRef(null);
  const [drm, setDrm] = useState({})

  useEffect(() => {
    setDrm({drm: {
      clearKeys: ck != null ? JSON.parse(atob(ck)) : {}
    }});
  }, [link, ck]);

  return <ShakaPlayer config={drm} autoPlay ref={controllerRef} src={link} />;

}

Sorry I didn't realize how simple it was to figure it out and this project is great. :heart: