videojs / videojs-contrib-eme

Supports Encrypted Media Extensions for playback of encrypted content in Video.js
Other
203 stars 72 forks source link

Can't get beyond "player.eme is not a function" #152

Closed darcyrailip closed 2 years ago

darcyrailip commented 2 years ago

I tried implementing this in my React app and keep encountering: player.eme is not a function.

The React app was using the NPM package.

For convenience, here's a simple HTML showing the same error:

<!DOCTYPE html>
<html lang="en">
  <head>
    <link href="https://vjs.zencdn.net/7.10.2/video-js.min.css" rel="stylesheet">
    <script src="https://unpkg.com/video.js/dist/video.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/videojs-contrib-eme@4.0.0/dist/videojs-contrib-eme.cjs.min.js"></script>
    <script>
      const loadSource = () => {

        var player = videojs('my-player', {}, function onPlayerReady() {

          videojs.log('Your player is ready!');

          this.src({
            src: "https://vjs.zencdn.net/v/oceans.mp4"
          })

          // In this context, `this` is the player that was created by Video.js.
          this.play();

          // Shouldn't this work?
          this.eme();

          // Also this won't work:
          player.eme()
        });
      }
    </script>
  </head>
  <body>
    <button onClick="loadSource()">Load Source</button>
    <br/><br/>
    <video
      id="my-player"
      class="video-js"
      controls
      preload="auto"/>
  </body>
</html>

Once I hit the button "Load Source", the console spits out the same error.

I feel like I'm missing something extremely obvious, but I'm not sure what it is.

mister-ben commented 2 years ago

The error is correct in this case because the function is replaced with an object when the plugin has initialised. this.eme() initialises the plugin, so player.eme is now an object. It should only be called once.

darcyrailip commented 2 years ago

The error is correct in this case because the function is replaced with an object when the plugin has initialised. this.eme() initialises the plugin, so player.eme is now an object. It should only be called once.

Sorry, I meant to just showcase the two options that I'd tried. Using both this.eme() and player.eme() don't work.

image

mister-ben commented 2 years ago

Look at this example, based on your code above. The type of eme is logged to the console before each call. https://jsbin.com/zijevigabi/edit?html,console,output

this.eme() does "work" here, it's being called (without options) and initialising. If you're not getting playback with protected content then there's probably configuration missing. It would be helpful to focus on a reduced test case of the actual implementation.

darcyrailip commented 2 years ago

Thanks for the example. Looks like my import of:

https://cdn.jsdelivr.net/npm/videojs-contrib-eme@4.0.0/dist/videojs-contrib-eme.cjs.min.js

Needed to be, as you mentioned:

https://cdn.jsdelivr.net/npm/videojs-contrib-eme@4.0.0/dist/videojs-contrib-eme.min.js