Offline DRM Assets
This guide shows how to use offline (downloaded) DRM-protected assets.
On this page:
LocalAssetsManager
The class that manages offline assets is called LocalAssetsManager.
LocalDataStore
LocalDataStore is an interface used by LocalAssetsManager to persist license data. The default implementation stores the licenses in a SharedPreferences file.
Applications should only customize LocalDataStore if they need to store the license files in another facility such as a db.
Create an instance
To use the default LocalDataStore, use the constructor that takes just the Context
object.
The manager needs to be stored in a member (or a singleton).
Register a new asset
Registering a downloaded asset includes connecting to the DRM server to acquire a Widevine license and securely storing that license locally for later.
Call the following method
void registerAsset(@NonNull final PKMediaSource mediaSource, @NonNull final String localAssetPath,
@NonNull final String assetId, final AssetRegistrationListener listener)
mediaSource
: aPKMediaSource
object with full parameters of the original (remote) file. Must contain adrmData
list with aPKDrmParams
objectlocalAssetPath
: full path to the downloaded asset (in DASH, this is the mpd file)assetId
: any id that uniquely identifies the assetlistener
: a listener that will be called upon success or failure of the registration process. The listener has two methods -onRegistered()
andonFailed()
.
Unregister an asset
Before deleting an asset from storage, the application should tell LocalAssetsManager
to remove the license linked with it. This is done by calling:
void unregisterAsset(@NonNull final String localAssetPath,
@NonNull final String assetId, final AssetRemovalListener listener)
localAssetPath
: the path that was passed toregisterAsset()
. The asset must still exist at this pointassetId
: the assetId that was passed toregisterAsset()
listener
: a listener that will be called upon success of the unregistration process.
Renew asset license
If the backend allows it, the asset license can be renewed (extended).
void refreshAsset(@NonNull final PKMediaSource mediaSource, @NonNull final String localAssetPath,
@NonNull final String assetId, final AssetRegistrationListener listener)
mediaSource
: aPKMediaSource
object like the one passed toregisterAsset()
, with fresh DRM paramslocalAssetPath
: the path that was passed toregisterAsset()
assetId
: the assetId that was passed toregisterAsset()
listener
: a listener that will be called upon success or failure of the renew process. The listener has two methods -onRegistered()
andonFailed()
.
Check asset status
To check the validity and expiration of a downloaded asset, the app can call the following function:
void checkAssetStatus(@NonNull final String localAssetPath, @NonNull final String assetId,
@Nullable final AssetStatusListener listener)
localAssetPath
: the path that was passed toregisterAsset()
assetId
: the assetId that was passed toregisterAsset()
listener
: a listener that will be called with the status of the asset.
The listener has one method, onStatus()
. It accepts 4 arguments:
void onStatus(String localAssetPath, long expiryTimeSeconds, long availableTimeSeconds, boolean isRegistered);
localAssetPath
: the path that was passed toregisterAsset()
expiryTimeSeconds
: number of seconds until the license is no longer valid and a renew is requiredisRegistered
: true if the asset is registered, false otherwise
availableTimeSeconds
is for extended business logic that is not commonly used. It refers to rental duration.
More info
For more info on downloading, see Download to Go.