Interface OfflineDrmCallbackProvider


public interface OfflineDrmCallbackProvider
Supplies the host's MediaDrmCallback for a downloaded item, on demand, for as long as the process lives.

Register one with OfflineDownloadFactory.setOfflineDrmCallbackProvider(OfflineDrmCallbackProvider) and the SDK will ask it whenever it needs a callback for offline DRM work: acquiring an offline licence for a download, and releasing that licence when the download is removed.

Why this exists. A callback attached to a PlaylistItem is only remembered by the OfflineDownloadManager that prepared the download, and that registry is emptied by OfflineDownloadFactory.destroyAll(). It is not persisted either - the data stored with a download is JSON, and marshalling a Parcelable into durable storage is not supported, because the format is not stable across releases. So the ordinary flow - download an item, leave the screen, come back later and delete it - had no callback to release the licence with, and an item configured with a callback and no licence URL got no release at all. A provider re-registered on every launch closes both gaps without the SDK persisting anything.

Register it from Application.onCreate(), so it is in place before any screen asks for a download:


 @Override
 public void onCreate() {
     super.onCreate();
     OfflineDownloadFactory.setOfflineDrmCallbackProvider(
             mediaId -> new MyDrmCallback(getApplicationContext(), mediaId));
 }
 

Do not capture an Activity - not in the provider, and not in the callbacks it returns. The SDK holds the provider for the life of the process, so anything it captures is held that long too. Capture the application context, or nothing at all. This is the whole reason the API is a provider rather than a process-wide map of callbacks: the object graph a host's callback drags along is the host's to control, and registering from Application makes application scope the natural choice.

Precedence. A callback set on the PlaylistItem handed to OfflineDownloadManager.prepareMediaDownload(android.content.Context, com.jwplayer.pub.api.media.playlists.PlaylistItem) still wins for that item, so existing integrations behave exactly as before. The provider is the fallback, consulted only when there is no per-item callback - which is every case the per-item registry cannot cover.

This is called on the main thread when a download is removed, and must return quickly. Only the licence work itself moves to a background thread; the provider is asked for the callback first, on whichever thread the removal is reported on, which for a removal is the main thread. Do not fetch a token, read a file or touch the network inside getMediaDrmCallback(String) - do that inside the MediaDrmCallback you return, which is invoked on a background thread. Implementations must also be safe to call from any thread, since acquisition can ask from elsewhere.

The callback you return is responsible for knowing where to send the request. When the SDK has a callback it uses it for the whole exchange, and does not fall back to the licence URL stored with the download. That matters most on a release: a release key request carries an empty licence-server URL, so a callback that posts to KeyRequest.getLicenseServerUrl() - the usual pattern for a streaming callback - will post to nothing. Give the returned callback its own licence endpoint. A provider that returns a callback for an item whose release previously worked from the stored URL will otherwise break that release, and the failure is reported but not fatal.

Returning null is fine and simply means "no callback for this item"; the SDK then falls back to the licence URL stored with the download. A provider that throws is treated the same as one returning null - the failure is logged and the offline operation carries on.

  • Method Summary

    Modifier and Type
    Method
    Description
    The callback to use for the given item's offline licence work, or null if this item does not need one.