DRM with ReactJS

Guide to set up Widevine & Fairplay DRM with GumletReactPlayer on ReactJS

Gumlet React Player is a player to play DRM protected videos on react web applications. It can play both HLS and DASH streams and supports DRM.

To keep the scope of this document limited we expect you have already setup React JS development environment and have an application running.

📹

Protect your video assets from piracy.

Easily enable secure video playback with Widevine and Fairplay DRM on your ReactJS applications with Gumlet.

Step 1: Install the react-embed-player package

npm i @gumlet/react-embed-player

Step 2: Add the GumletPlayer

For the simplicity of this document we are making the changes in App.js itself and our web application would only have a video player in it.

import React, { Component } from 'react'

import {GumletPlayer} from '@gumlet/react-embed-player'

class Example extends Component {
  render() {
    return <GumletPlayer
      videoID="64bfb0913ed6e5096d66dc1e"
      title="Gumlet Player Example"
      style={{height: "100vh", width: "100vw", position:"relative"}}
      schemaOrgVideoObject={{"@context":"https://schema.org","@type":"VideoObject","name":"Gumlet","description":"","embedUrl":"https://play.gumlet.io/embed/64bfb0913ed6e5096d66dc1e"}}
      autoplay={false}
      preload={false}
      muted={true}
    />
  }
}

...

Example

import React, { useRef } from 'react';

import {GumletPlayer} from 'react-embed-player'
import 'react-embed-player/dist/index.css'

const App = () => {
  const playerRef = useRef(null);
  
  const play = () => {
    if(playerRef.current) playerRef.current.play();
  }
  const pause = () => {
    if(playerRef.current) playerRef.current.pause();
  }
  const mute = () => {
    if(playerRef.current) playerRef.current.mute();
  }
  const unmute = () => {
    if(playerRef.current) playerRef.current.unmute();
  }
  const setVolume = (volume) => {
    if(playerRef.current) playerRef.current.setVolume(volume);
  }
  const setCurrentTime = (time) => {
    if(playerRef.current) playerRef.current.setCurrentTime(time);
  }
  const setPlaybackRate = (rate) => {
    if(playerRef.current) playerRef.current.setPlaybackRate(rate);
  }
  const getVolume = async () => {
    if(playerRef.current) window.alert(await playerRef.current.getVolume());
  }
  const getDuration = async () => {
    if(playerRef.current) window.alert(await playerRef.current.getDuration());
  }
  const getCurrentTime = async () => {
    if(playerRef.current) window.alert(await playerRef.current.getCurrentTime());
  }
  const getPlaybackRate = async () => {
    if(playerRef.current) window.alert(await playerRef.current.getPlaybackRate());
  }
  

  return <>
    <div style={{padding: "10px"}}>
      <button onClick={play}>Play</button>
      <button onClick={pause}>Pause</button>
      <button onClick={mute}>Mute</button>
      <button onClick={unmute}>Unmute</button>
      <button onClick={() => setVolume(50)}>Set volume to 50%</button>
      <button onClick={() => setCurrentTime(2)}>Set time to 2 seconds</button>
      <button onClick={() => setPlaybackRate(2)}>Set playback rate to 2x</button>
      <button onClick={getVolume}>Get volume</button>
      <button onClick={getDuration}>Get duration</button>
      <button onClick={getCurrentTime}>Get current time</button>
      <button onClick={getPlaybackRate}>Get playback rate</button>
    </div>
    <div style={{marginTop: "10px", padding:"10px"}}>
      <GumletPlayer
        ref={playerRef}
        videoID="64bfb0913ed6e5096d66dc1e"
        title="Gumlet Player Example"
        style={{height: "100vh", width: "100vw", position:"relative"}}
        schemaOrgVideoObject={{"@context":"https://schema.org","@type":"VideoObject","name":"Siren pink 3:4 video","description":"","thumbnailUrl":[["https://video.gumlet.io/603cc6a9926fb6233baebb34/66487345e3dcc416dc9bbb5b/thumbnail-1-0.png?v=1716024171990"]],"uploadDate":"2024-05-18T09:22:13.592Z","duration":"PT7.833333S","embedUrl":"https://play.gumlet.io/embed/66487345e3dcc416dc9bbb5b"}}
        autoplay={false}
        preload={false}
        muted={true}
        disable_player_controls={false}
        t={35}
        onReady={() => console.log("Player is ready.")}
        onPlay={() => console.log("Video is playing.")}
        onPause={() => console.log("Video is paused.")}
        onProgress={(e) => console.log("Video is at", e.percent)}
        onTimeUpdate={(e) => console.log("Video is at", e.seconds, "seconds, total duration ", e.duration, " seconds.")}
        onEnded={() => console.log("Video has ended.")}
        onFullScreenChange={(e) => console.log("Full screen change event", e)}
        onPipChange={(e) => console.log("Picture in picture change event", e)}
        onAudioChange={(e) => console.log("Audio changed event", e)}
        onQualityChange={(e) => console.log("Quality changed event", e)}
        onVolumeChange={(e) => console.log("Volume changed event", e)}
        onSeeked={(e) => console.log("Seeked event", e)}
        onError={(e) => console.log("Error event", e)}
      />
    </div>
  </>
}

export default App


Properties supported:

PropDescriptionDefault
videoID String RequiredVideo ID which is generated after processing the video on gumlet
title StringTitle of the iframeGumlet video player
style ObjectStyle tag passed on to the iframe container{padding:"56.25% 0 0 0", position:"relative"}
schemaOrgVideoObject Objectschema.org object which is added to a script tag{}
autoplay BooleanShould the video autoplayDefault set in collection settings
preload BooleanShould the video preloadDefault set in collection settings
muted BooleanShould the video player be mutedDefault set in collection settings
gm_user_id StringUser ID passed to gumlet insights objectnull
gm_user_name StringUser name passed to gumlet insights objectnull
gm_user_email StringUser email passed to gumlet insights objectnull
gm_custom_data_1 StringCustom data 1 passed to gumlet insights objectnull
loop BooleanShould the video play in a loopDefault set in collection settings
thumbnail StringURL Encoded value of the Poster/Thumbnail URL which should be shownDefault set in asset details
drm_token StringToken generated on backend for DRM Protected contentnull
expires IntegerToken expiry time from epoch in millis for DRM protected contentnull
vast_tag_url StringURL Encoded VAST tag URLnull
start_high_res BooleanStart the video in the highest resolution availablefalse
disable_seek BooleanDisable the seek bar and removes forward and rewind buttonsfalse
disable_player_controls BooleanRemoves all player controls from the playerfalse
watermark_text StringWatermark text to be shown in the playernull
facebook_pixel_id StringFacebook pixel ID to be used to send data about playbacknull
ga_tracking_id StringGoogle pixel ID to be used to send data about playbacknull
t IntegerThe playback instant in seconds to start the video atnull

Methods supported:

play: void
Play the media:

pause: void
Pause the media:

getPaused: boolean
Determine if the media is paused:

mute: void
Mute the media:

unmute: void
Unmute the media:

getMuted: boolean
Determine if the media is muted:

setVolume: void
Set the volume. Value needs to be between 0-100:

getVolume: number
Get the volume. Value will be between 0-100:

getDuration: number
Get the duration of the media is seconds:

setCurrentTime: number
Perform a seek to a particular time in seconds:

getCurrentTime: number
Get the current time in seconds of the video:

setPlaybackRate: number
Set the playback rate which are available in the player. Doesn't returns an error if the passed playback rate is not available.

getPlaybackRate: number
Get the current playback rate of the player:


Callbacks supported:

This player supports callback functions to give you better control over your video.

onReady - fired when the video is ready.

onProgress - fires when the video is loading additional media for playback:

{
  percent: 0.8,
}

onTimeupdate - fires during playback:

{
  seconds: 10,
  duration: 40
}

onPlay - fires when the video starts to play.

onPause - fires when the video is paused.

onEnded - fires when the video is finished.

onFullScreenChange - fires when the video fullscreen is changed:

{
  isFullScreen: true // or false
}

onPipChange - fires when the video is put to or brought back from picture-in-picture.

{
  isPIP: true // or false
}

onPlaybackRateChange- fires when the video playback rate is changed by user.

onAudioChange - fires when the audio track of video is changed.

onQualityChange - fires when the video quality is changed.

onVolumeChange - fires when the volume level of the player is changed. It also gets fired when the player is muted or unmuted, along with muted and unmuted events respectively.

{
  volume: 50
}

onSeeked - fires when the video has been seeked by the user. Gives seeked to time in seconds and total duration of video.

{
  seconds: 10
  duration: 50
}

onError - fires when an error occurs.