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 explicitly blocks all browsers except for a very narrow set of the most mainstream whitelisted browsers. For example, that is why Brave Browser was originally unable to play Netflix. So, I believe the only way to implement Netflix playback would be for you to reach an agreement with Netflix directly. I'm tracking this issue and will update this article if this changes in the future.

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.

Enabling Widevine for Android

For 3D WebView for Android, an application can enable Widevine DRM by calling AndroidWebView.SetDrmEnabled() at the start of the app, like this:

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

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

Enabling Widevine for Android Gecko

For 3D WebView for Android with Gecko Engine, an application can enable Widevine DRM by calling AndroidGeckoWebView.SetDrmEnabled() at the start of the 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 DRM for iOS

iOS doesn't support Widevine DRM, but FairPlay DRM is enabled by default.