videojs / videojs-contrib-eme

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

How to use this library to detect SupportedCDMs #191

Open vanminhquangtri opened 1 year ago

vanminhquangtri commented 1 year ago

I have used Videojs already and want to use videojs-contrib-eme to detect the support DRM key before apply the DRM. But I don't actually understand how to use detectSupportedCDMs(). I see it has player.eme.detectSupportedCDMs() but don't understand what is player here?

This is my main code: import 'videojs-contrib-eme'

window.player = window.videojs(
        videoElement,
        myConfigObject,
        () => {
          window.player.eme()
        }
)

But it keep show error: window.player.eme is not a function

lapalb commented 1 year ago

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.

vanminhquangtri commented 1 year ago

Hello @lapalb , I still can't get what you mean. A bit confused. If posible can you please give me a code sample. That's would be much easier to understand. Thank you.

vanminhquangtri commented 1 year ago

@lapalb it seem the plugin is added success. But the player.eme.detectSupportedCDMs() not work. it show error player.eme.detectSupportedCDMs is not a function Can you please advice how to fix this? Do I need to pass any param to player.eme() method? This is my code:

import('video.js').then(function ({ default: videojs }) {
        import('videojs-contrib-eme').then(function () {
          const videoNode = document.getElementById('videoPlayer')
          if (!videoNode) return
          videojs.registerPlugin('eme', videojsContribEme)
          const player = videojs(videoNode, {}, function () {
            try {
              player.eme()
              player.eme.detectSupportedCDMs().then((supportedCDMs) => {
                console.log(supportedCDMs)
              })
            } catch (e) {
              console.log(e)
            }
          })
        })
      })
damanV5 commented 1 year ago

@vanminhquangtri I am also facing the same issue, maybe they forgot to expose the function as I cannot see detectSupportedCDMs inside the eme object.