How to enable Widevine DRM?

Widevine is a type of DRM used by some websites to digitally protect content from being pirated and is commonly used by video and audio streaming sites like Spotify, YouTube, and Hulu. This article describes how to enable Widevine for the following 3D WebView packages:

Limitations

Even with Widevine DRM enabled, some video streaming sites still do not play in 3D WebView because they only support specific whitelisted browsers. Most notably, Netflix only whitelists major mainstream browsers and doesn't allow playback from within webviews.

Enabling Widevine for Android Gecko

Widevine DRM is easy to enable with 3D WebView for Android with Gecko Engine. All you need to do is call AndroidGeckoWebView.SetDrmEnabled() at the start of your app, like this:

void Awake() {
  #if UNITY_ANDROID && !UNITY_EDITOR
    AndroidGeckoWebView.SetDrmEnabled(true);
  #endif
}

After that, you can verify that DRM is enabled by viewing the DRM Stream Test on this page.

Enabling Widevine for Windows and macOS

The process of enabling Widevine for 3D WebView for Windows and macOS is more involved, and you need a license from Widevine in order to legally redistribute it. You can contact Widevine to request a license. The following steps describe how to use a copy of Widevine obtained from an installation of Google Chrome for testing. However, you should not actually redistribute a copy of Widevine without a license.

  1. First, enable the H.264 video codec like described in this article.
  2. Download and install the Google Chrome browser.
  3. Locate the WidevineCdm folder inside the local Chrome installation (e.g. C:\Program Files\Google\Chrome\Application\{version}\WidevineCdm) and then copy the x64 widevinecdm.dll and manifest.json files to the following folder in the Unity project: Assets/StreamingAssets/widevine.
  4. Update the manifest.json file to append the following two fields to the root of the JSON document:
{
  ...
  "os": "win",
  "arch": "x64"
}
  1. At the start of your app, use StandaloneWebView.SetCommandLineArguments() to pass Chromium the path to the Widevine folder, like this:
void Awake() {
  var wideVineFolderPath = Path.Combine(Application.streamingAssetsPath, "widevine");
  StandaloneWebView.SetCommandLineArguments($"--widevine-cdm-path=\"{wideVineFolderPath}\"");
}

After that, you can verify that DRM is enabled by viewing the DRM Stream Test on this page. The steps for macOS are the same, except "os": "mac" should be used instead.