---
updatedAt: 2026-09-10T09:14:42.000Z
agentTools:
  siteIndex: https://docs.jwplayer.com/llms.txt
  projectIndex: https://docs.jwplayer.com/players/llms.txt
---

# ANDROID: Set up a player with offline DRM content

```java Java
JSONObject dapi = new JSONObject(playlistJson);
JSONArray array = dapi.getJSONArray(PARAM_PLAYLIST);
JSONObject json = array.getJSONObject(0);

// Required Fields
String file = "";
String licenseUrl = "";
String mediaId = json.getString("mediaid");

JSONArray sourcesJson = json.getJSONArray("sources");
for (int i=0; i<sourcesJson.length(); i++) {
	JSONObject source = sourcesJson.getJSONObject(i);
	if (source.has("drm")) {
		JSONObject drmJson = source.getJSONObject("drm");
		if (drmJson.has("widevine")) {
			JSONObject widevine = drmJson.getJSONObject("widevine");
			licenseUrl = widevine.optString("url");
			file = source.getString("file");
		}
	}
}

DrmConfig drmConfig = new DrmConfig.Builder()
		.licenseUri(licenseUrl)
		.build();
PlaylistItem item = new PlaylistItem.Builder()
		.file(file)
		.mediaId(mediaId)
		.drmConfig(drmConfig)
		.build();
...

DrmDownloadManager mDrmDownloadManager = OfflineDrmFactory.getDrmDownloadManagerFor(context, mediaId);
mDrmDownloadManager.prepareMediaDownload(
        context,
        item,
        downloadOptionsListener
);

mDrmDownloadManager.downloadMedia(context,
                                  videoOption,
                                  audioOption
);

...

mPlayer.setup(new PlayerConfig.Builder()
			  .playlist(new ArrayList<PlaylistItem>() {{
				  add(mDrmDownloadManager.getDownloadedPlaylistItem(mediaId));
			  }})
			  .build()
);

// End the Activity
@Override
protected void onDestroy() {
    super.onDestroy();
    OfflineDrmFactory.destroyAll();
}

// Remove downloads
mDrmDownloadManager.removeDownload(context, mediaId);
```

# Parse the playlist JSON from retrieve the API response into a PlaylistItem with a DrmConfig.

<!-- java@1-30 -->

> ⚠️
> Prior to starting this step, complete the first two steps in <a href="https://docs.jwplayer.com/players/docs/android-configure-offline-drm" target="_blank">Configure offline DRM (Android v4)</a>.

# Prepare the download.

<!-- java@33-38 -->

You can now get a `DrmDownloadManager` and prepare to download media.

The `DrmDownloadManager` checks to see which video and audio renditions are available for download and notifies the provided `MediaDownloadResultListener`.

You must choose how to display the renditions for the user to select.

# Download the media.

<!-- java@40-43 -->

Once the download is complete, the `MediaDownloadResultListener` will be notified that the media with the specific media ID has been downloaded.

# Set up the player with offline DRM content.

<!-- java@47-52 -->

> 📘
> If you want to play offline DRM content, you must set up with *offline* DRM content as shown above. Setting up with *online* DRM content will not play content when you are offline.

# Manage the lifecycle.

<!-- java@55-59 -->

When you are all done with the Activity, you must call this `onDestroy()`.

# Remove download from the device.

<!-- java@62 -->

Use this line to remove the downloaded media from the device.