Chromecast (JW Platform)

Integrate Studio DRM with your JW Platform and Chromecast

The Google Cast framework enables a viewer to stream content to a compatible TV or sound system. By enabling the Google Cast framework in your app, a viewer can use a cast button to stream your content to a Cast-enabled device on a shared network.

This article explains two integrations:

  • Enabling the Google Cast framework for the JW web player
  • Casting video content protected by Studio DRM with the JW Platform

πŸ“˜

VUDRM was rebranded as Studio DRM following JW Player’s acquisition of Vualto. Any references to VUDRM in this document or in the Studio DRM Admin portal refer to Studio DRM.



Requirements

Integrating Studio DRM with JW Platform and Chromecast has several requirements.

Item Notes
Application Registration Registration allows you to test your custom receiver. Specifically, you will be able to connect to the custom receiver with your custom Cast implementation.
Cast App A Cast app enables DRM-protected content to be streamed on a Cast-enabled device.

A Cast app consists of two components:
  • Sender app (JW web player)
  • Custom web receiver
You can use the JW Player Chromecast Custom Receiver Demo App to guide your implementation.

NOTE: Google recommends installing a mix of http-server and ngrok to deploy your receiver locally.
Content URLs Through a signed URL, the license URL and streaming URL for each media ID are retrieved.

Use the following steps to retrieve the content URLs:
  1. Use this sample code to generate the signed URL.
  2. Make a GET call with the signed URL.
  3. From the API response, extract the license and streaming URLs from the following parameters:
    • playlist[].sources.drm.widevine.url (license)
    • playlist[].sources.drm.file (streaming)

// Signed URL response - Delivery API sample
{
   "title":"Sintel.2010.1080p",
   "kind":"Single Item",
   "playlist":[
      {
         ...
         "sources":[
            {
               "drm":{
                  "widevine":{
                     "url":"<widevine-license-url>"
                  },
                  ...
               },
               "file":"<dash-stream-url>",
               "type":"application/dash+xml"
            },
            ...
         ]
      }
   ],
   ...
}


Configure the Cast app

For DRM playback, deploy your custom web receiver.


<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Studio DRM Custom Chromecast Receiver</title>
    <link rel="stylesheet" href="main.css" media="screen" />
    <script src="//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"></script>
</head>

<body>
    <cast-media-player></cast-media-player>
</body>
<footer>
    <script src="receiver.js"></script>
</footer>
</html>
(() => {
    const context = cast.framework.CastReceiverContext.getInstance();
    const playerManager = context.getPlayerManager();
    var laurl;

    // Wait until the cast player is loaded, get the laurl from the media request and use it in the player config
    playerManager.setMessageInterceptor(cast.framework.messages.MessageType.LOAD, loadRequestData => {
        let customData = loadRequestData.media.customData;
        // Check all content source fields for asset URL or ID
        let source = loadRequestData.media.contentUrl || loadRequestData.media.entity || loadRequestData.media.contentId;
        if (!source || source == "") {
            let error = new cast.framework.messages.ErrorData(
                cast.framework.messages.ErrorType.LOAD_FAILED
            );
            error.reason = cast.framework.messages.ErrorReason.INVALID_REQUEST;
            return error;
        }

        loadRequestData.media.contentUrl = source;

        if (customData) {
            if (customData["laurl"]) {
                laurl = customData["laurl"];
            } else if (customData["drm"]["widevine"]["url"]) {
                laurl = customData["drm"]["widevine"]["url"];
            }
        }
        playerManager.setPlaybackConfig(createPlaybackConfig(playerManager));
        return loadRequestData;
    });

    context.start();

    function createPlaybackConfig(playerManager) {
        let playbackConfig = (Object.assign(new cast.framework.PlaybackConfig(), playerManager.getPlaybackConfig()));
        playbackConfig.licenseUrl = laurl;
        playbackConfig.protectionSystem = cast.framework.ContentProtection.WIDEVINE;
        return playbackConfig;
    }

})();


Enable casting for a viewer

Once you set up your custom receiver, you will be able to cast DRM content from the JW web player. For reference, you may see our Studio DRM integration with JW Player.

  1. Add the cast object to your setup.
  2. In the JW Player studiodrm-jwplayer.js file, define dash-stream-url with your signed streaming URL.
  3. Define widevine-license-url with the signed license URL.
  4. Define your-receiver-application-id with your registered custom receiver app ID from the Google Cast developer console.
(function() {

    // Set the mpeg-dash stream URL.
    var dashStreamURL = "<dash-stream-url>"

    // Set the hls stream URL.
    var hlsStreamURL = "<hls-stream-url>";

    // Set the URL to retrieve the fairplay certificate from.
    var fairplayCertURL = "<fairplay-cert-url>";

    // setup jwplayer, passing the stream URLs and DRM configurations.
    jwplayer("studiodrm-container").setup({
        "playlist": [{
            "sources": [{
                "file": dashStreamURL,
                "drm": {
                    "widevine": {
                        "url": "<widevine-license-url>"
                    },
                    "playready": {
                        "url": "https://playready-license.vudrm.tech/rightsmanager.asmx",
                    }
                }
            },
            {
                "file": hlsStreamURL,
                "drm": {
                    "fairplay": {
                        "certificateUrl": fairplayCertURL,
                        "processSpcUrl": function (initData) {
                            return "https://" + initData.split("skd://").pop();
                        },
                        "licenseRequestHeaders": [
                            {
                                "name": "Content-type",
                                "value": "arraybuffer"
                            }
                        ]
                    }
                }
            }]
        }],
        "cast": {
            "appid": "<your-receiver-application-id>"
        }
    });
})();

You can now cast DRM-protected video content onto a Chromecast device.



FAQ

How do I implement Airplay with DRM media?

Airplay will automatically be implemented by the Apple OS with DRM Media.

πŸ“˜

If an Airplay session is initiating after 10 minutes or longer of playback on the sending device, playback on the receiving device will fail. The user will need to restart the video in the Airplay session. This occurs because the Airplay receiver is using the existing authorization which has timed out.