Play DRM-protected content (Android v3)

Learn how to enable digital rights management (DRM) protected playback for an Android app.

Digital rights management depends upon the hardware that is being used and allows you to protect the digital media in your app. On Android 4.3+, DRM-protected playback is supported for any DRM scheme for which a modular DRM component exists on the device. All Android devices are required to support Widevine modular DRM (with L3 security, although many devices also support L1).


The JWP SDK does not support offline DRM.


  • Android 4.3+
  • DRM license server URL

Supported DRM provider

Google Widevine


Not all Android devices may have secure decoders for every video codec. You can use Android's MediaCodecList class to find out if secure playback for a particular codec is supported on a device.

Configure the playback

Regardless of the DRM provider that you use, the following steps generally apply to enable the playback of DRM-protected content:

  1. Add a to your project. This utility is used by the MediaDrmCallback class to download data.
public class Util {

    public static byte[] executePost(String url, byte[] data, Map < String, String > requestProperties)
    throws IOException {
        HttpURLConnection urlConnection = null;
        try {
            urlConnection = (HttpURLConnection) new URL(url).openConnection();
            urlConnection.setDoOutput(data != null);
            if (requestProperties != null) {
                for (Map.Entry < String, String > requestProperty: requestProperties.entrySet()) {
                    urlConnection.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
            // Write the request body, if there is one.
            if (data != null) {
                OutputStream out = urlConnection.getOutputStream();
                try {
                } finally {
            // Read and return the response body.
            InputStream inputStream = urlConnection.getInputStream();
            try {
                return toByteArray(inputStream);
            } finally {
        } finally {
            if (urlConnection != null) {
  1. Add the appropriate DRM provider callback .java file to your project. Contact your DRM provider for its suggested MediaDrmCallback implementation for Android.

    For the following generic Widevine implementation example, assume that each new PlaylistItem requires a unique contentId and provider. This implementation enables you to specify these required values for every instance of WidevineMediaDrmCallback.
public class WidevineMediaDrmCallback implements MediaDrmCallback {

    private static final String WIDEVINE_GTS_DEFAULT_BASE_URI =

    private final String defaultUri;

    public WidevineMediaDrmCallback(String contentId, String provider) {
        String params = "?video_id=" + contentId + "&provider=" + provider;
        defaultUri = WIDEVINE_GTS_DEFAULT_BASE_URI + params;

    public byte[] executeProvisionRequest(UUID uuid, ExoMediaDrm.ProvisionRequest request) throws IOException {
        String url = request.getDefaultUrl() + "&signedRequest=" + new String(request.getData());
        return Util.executePost(url, null, null);

    public byte[] executeKeyRequest(UUID uuid, ExoMediaDrm.KeyRequest request) throws IOException {
        String url = request.getLicenseServerUrl();
        if (TextUtils.isEmpty(url)) {
            url = defaultUri;
        return Util.executePost(url, request.getData(), null);

  1. Set the video URL of your DRM-protected video to a PlaylistItem (file).
  2. Create a new instance of your MediaDrmCallback implementation and set it to the PlaylistItem.
// Create a list to contain the PlaylistItems
List<PlaylistItem> playlist = new ArrayList<>();

// Add a PlaylistItem pointing to the first piece of content
PlaylistItem content = new PlaylistItem.Builder()
  .mediaDrmCallback(new WidevineMediaDrmCallback("{insert_content_id}", "{insert_provider}"))

// Add the content to the playlist