Search code examples
chromecastgoogle-castdrmgoogle-cast-sdk

How to DRM Content in chromecast


we are trying to play drm MPD content from Chrome to Chromecast Our receiver app code is as follow:

const context = cast.framework.CastReceiverContext.getInstance();
const playbackConfig = new cast.framework.PlaybackConfig();
playbackConfig.licenseUrl = 'http://widevine/yourLicenseServer';
playbackConfig.protectionSystem = cast.framework.ContentProtection.WIDEVINE;
playbackConfig.licenseRequestHandler = requestInfo => {
  requestInfo.withCredentials = true;
};
context.start({playbackConfig: playbackConfig});

// Update playback config licenseUrl according to provided value in load request.
context.getPlayerManager().setMediaPlaybackInfoHandler((loadRequest, playbackConfig) => {
if (loadRequest.media.customData && loadRequest.media.customData.licenseUrl) {
 playbackConfig.licenseUrl = loadRequest.media.customData.licenseUrl;
 }
 return playbackConfig;
});

I don't get a correct way to pass custom data for drm in the client application. please help.


Solution

  • I think you are asking how you send the license URL from the sender client (the device 'casing') to the receiver (the device which will receive the request to cast and which actually get and plays the stream) in the custom data.

    The custom data is a JSON object and you just need to put the license url into it.

    There are two common ways of passing this custom data:

    • include it in the MediaInfo object using the MediaInfo.Builder.setCustomData method
    • include it the MediaLoadOptions data

    As an example, looking at a MediaInfo example form the Google documents and adding in custom data:

    List tracks = new ArrayList();
    tracks.add(englishSubtitle);
    tracks.add(frenchSubtitle);
    tracks.add(frenchAudio);
    MediaInfo mediaInfo = MediaInfo.Builder(url)
      .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
      .setContentType(getContentType())
      .setMetadata(getMetadata())
      .setMediaTracks(tracks)
      .setCustomData(yourCustomData)    <--- This is the custom data
      .build();
    

    'yourCustomData' above is a JSON object which you create and add your data to, in your case your license server URL:

    JSONObject yourCustomData = new JSONObject();
    try {
        yourCustomeData.put("licenseURL", "HTTPS://yourlicenseServerUrl.com");
    } catch (JSONException e) {
        // Add any error code you want here
        e.printStackTrace();
    }