How to Embed an HTML5 Video Player with DRM Protection?

Haihaisoft's DRM-X 5.0 for HTML5 Video, it's using HTML5 Video tag. Content providers can easily embed video using standard HTML5 Video tag, and using famous HTML5 Player such as VideoJS, and using JavaScript to interact with HTML5 Player.

More Tutorials
How to Embed an HTML5 Video Player with DRM Protection?

How to Embed an HTML5 Video Player with DRM Protection?

If you don't need to deeply modify the player, please use the code below to embed the video.

<div id="ZJGet_Video_URL" style="display: none;">https://www.drm-x.com/download/drmx5/HolyForever-ChrisTomlin_P.mp4</div>
<script type="text/javascript" src="https://www.zjget.com/assets/embed_js/embed_zjget.js"></script>
<script type="text/javascript" src="https://www.zjget.com/assets/videojs-8.23.3/video.min.js"></script>
<script type="text/javascript" src="https://www.zjget.com/assets/embed_js/zjget.js"></script>

If you need to modify the player, please refer to the following introduction.

Include VideoJS in head:

<!--Include VideoJS library-->
<link rel="stylesheet" type="text/css" href="css/video-js.css" />
<script src="js/video.js" type="text/javascript" charset="utf-8"></script>

<!--Using VideoJS skin-->
<link rel="stylesheet" type="text/css" href="css/skin/TechSkin-skin.css" />

You can also use the other skin according to the style of your website.

Here we recommend a VideoJS skin generation tool, you can customize the player skin. https://codepen.io/heff/pen/EarCt

Embed VideoJS:

Note:For iOS, please add a div with the id value of zjget_ios_media_url, hide the div, write the video url in the div, ZJGet will automatically recognize the tag, and prompt the user whether to play this video. such as:

<div id="zjget_ios_media_url" style="display: none;">https://www.drm-x.com/download/drmx5/HolyForever-ChrisTomlin_P.mp4</div>

The latest version of ZJGet for iOS media URL notes:

If you want your customers to play your videos on iOS, you must have the following characteristics in the link, with _P. For example, the link contains _P.mp4, _P.webm or _P.mp3, which is case-insensitive. Or contains zjget. You can include one of these characteristics in any location on the download link, then ZJGet for iOS recognizes and supports downloads.

<div id="LoadingText" style="display: none;" align="center">
  Please wait, connecting to obtain license page...
</div>
<div id="cellular_button" align="center"></div>
<div align="center">
  <script type="text/javascript">
    // Detecting current browser, if not ZJGet, It Will remind the user to open the protected files in ZJGet browser,
    // and remind the user to download ZJGet browser.
    if(navigator.userAgent.indexOf("ZJGet") == -1){
      document.write('Please open the protected files in ZJGet browser. Download ZJGet');
    }else{
      // Use HTML5 video tag;
      // ZJGet will automatically change the video tag's ID,
      // here zjget_player will automatically become zjget_player_html5_api;
      // Use src attribute specifies video URL;
      // class="video-js" using VideoJS style.
      // In data-setup, use "autoplay":true; add auto play control;
      // In data-setup, you can use "playbackRates": [0.5, 0.7, 1, 1.5, 2, 3, 4] add control speed function.;
      document.write('<'video id="zjget_player" controls="controls" class="video-js" data-setup=\' {"playbackRates": [0.5, 0.7, 1, 1.2, 1.5, 2], "autoplay":false, "width": 856, "height": 480 }\'><'source src="https://www.drm-x.com/download/drmx5/HolyForever-ChrisTomlin_P.mp4" type="video/mp4"></video>);
    }
  </script>
</div>

Javascript Code:

<script type="text/javascript">
  document.onreadystatechange = function() {
    if (document.readyState == "complete") { // After the page is complete, and execute,Required;

      // Get HTML5 player
      // ZJGet will automatically change zjget_player become zjget_player_html5_api;
      myVid=document.getElementById("zjget_player_html5_api");

      // Get detail information return by the player, 

      // if user need to obtain a license, It will return a URL;

      // Otherwise, It will return the details of the protected file information and the license information.
      isSupp=myVid.canPlayType('zjget');
	// Check the mobile phone network type
      if(navigator.userAgent.indexOf("Mobile ZJGet") > 0){
		var con = window.navigator.connection;
		var network = con.type; // Mobile phone network:cellular; wifi:wifi
		// Check whether your phone is using a mobile network or wifi
		if (network == "cellular"){ // If the phone is using a mobile network, you need to add a button to get a license to the page
			document.getElementById("cellular_button").innerHTML = '<'button style="height: 50px" class="m_g_b" onClick="supportType(event,\'video/ogg\',\'theora, vorbis\')">Play Protected file (Click 2 times)'<'/button>;
		}
	  }
      // If the information contained in the return message contains URL,

      // it is required to obtain a license.
      if(isSupp.indexOf("http")>0){
        // Just a tips, non - must;
        document.getElementById("LoadingText").style.display='block';
        // Using substring to capture a URL to obtain license;
        licURL = isSupp.substring(isSupp.indexOf("http"));
        // Redirecting to obtain license page to verify and obtain license.
        window.location.href = licURL;
      }
    }
};
</script>

The following method provides a reference to obtain more information, including the license information (Open Count and Expiration Date), you can get this information according to your requirements.

function supportType(e,vidType,codType){
  myVid=document.getElementById("zjget_player_html5_api");
  isSupp=myVid.canPlayType("zjget");
  myVid.play();
  licURL = isSupp.substring(isSupp.indexOf("http"));

  if(isSupp.indexOf("http")>0){
    window.location.href = licURL;
  }else{
    if(isSupp.indexOf("License")>0){

      // Get open count
      var openCount=isSupp.substring(isSupp.indexOf(":"),isSupp.indexOf(";"));

      // Get the license expiration date
      var ft=isSupp.substring(isSupp.indexOf(";")+1);
      var ut = filetime_to_unixtime(ft);
      var d = new Date(ut * 1000);
      e.target.parentNode.innerHTML ="Open Count" + openCount + ", Expiration date:" + d.toLocaleString();
      return;
    }

    if(isSupp.indexOf("Error ID = 3")>0){
      e.target.parentNode.innerHTML ="License is expired, Please Re open the protected file to obtain a new license.";
      return;
    }
  }
}

Other DRM-X 5.0 Tutorials

DRM-X 5.0 ZJGet Windows Video TutorialDRM-X 5.0 ZJGet Windows Encryption Tutorial

This video will demonstrate how to encrypt files on Windows using ZJGet browser.

WATCH NOW
DRM-X 5.0 ZJGet macOS Video TutorialDRM-X 5.0 ZJGet macOS Encryption Tutorial

This video will demonstrate how to encrypt files on macOS using ZJGet browser.

WATCH NOW
DRM-X 5.0 ZJGet Windows TutorialDRM-X 5.0 ZJGet Windows Tutorial

This video will show you how to download, install, and open encrypted files on Windows using the ZJGet browser.

WATCH NOW
DRM-X 5.0 ZJGet Text TutorialDRM-X 5.0 ZJGet Text Tutorial

ZJGet Browser User Guide. This tutorial will help you easily master the core features and practical tips of the ZJGet browser.

WATCH NOW
DRM-X 5.0 ZJGet Graphic Tutorial AnswersDRM-X 5.0 ZJGet FAQ

Frequently Asked Questions (FAQ) about using ZJGet Browser. This section compiles the most useful Q&As to help you overcome any obstacles you may encounter.

WATCH NOW
DRM-X 5.0 自动批量加密工具完整操作指南DRM-X 5.0 Automatic Batch Encryption Tool full operation guide

The DRM-X 5.0 Automated Batch Encryption Tool offers both manual and automatic scanning modes, supports multiple file formats, and enables PDF-to-HTML encryption, helping businesses efficiently and automatically implement digital rights management for batch files.

WATCH NOW

Questions?

Our reps have answers.

Ask about Haihaisoft products, pricing, implementation, or anything else — our highly trained reps are standing by, ready to help.

Tel: +64 27 507 9959 (New Zealand)

QQ: 1279126286 / 994184623

Contact us on Microsoft Teams

service#haihaisoft.com (replace # into @)

Contact Us
contactUs