Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
darcyrailip opened this issue Nov 23, 2021 · 4 comments
Closed

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

darcyrailip opened this issue Nov 23, 2021 · 4 comments

Comments

@darcyrailip
Copy link

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/[email protected]/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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

Thanks for the example. Looks like my import of:

https://cdn.jsdelivr.net/npm/[email protected]/dist/videojs-contrib-eme.cjs.min.js

Needed to be, as you mentioned:

https://cdn.jsdelivr.net/npm/[email protected]/dist/videojs-contrib-eme.min.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants