DRM offline playback
Hello, I wrote a question about type of key on Thursday here: https://github.com/google/ExoPlayer/issues/1020 I accept your answer and thank you for that. I would like to ask some additional questions.
- Could you tell, please, if you are planning support of offline DRM playbacks in Exoplayer? If yes, do you know approximately when?
- Could you provide me some materials or examples, how can I do it? Because I don't have too much experience with this, I would like to know, how complicated is implementation of this feature. Maybe it will be better for me to wait until this feature will be standard part of Exoplayer (see 1. question).
- In my current implementation, I parse MPD file, download all video and audio segments, save them into the persistent storage of device and then I modify the location of segments in manifest to stored segments. This works fine, and now I only need to implement feature for acquiring offline type of DRM licence. Do you think that this is a correct approach?
Thank you very much in advance for your answers and ideas.
Hi, can you share your code about download and save ?
i change the source cdoe, there are 3 key steps: in StreamingDrmSessionManager 1 : keyRequest = mediaDrm.getKeyRequest(sessionId, schemeInitData.data, schemeInitData.mimeType, MediaDrm.KEY_TYPE_OFFLINE, optionalKeyRequestParameters); 2: in the onKeyResponse method, final byte[] result=mediaDrm.provideKeyResponse(sessionId, (byte[]) response); the result actually is a keySetID which is used to restore license. you need to store it locally, 3: in the postKeyRequest() method, first check whether has keySetID, it existed, call mediaDrm.restoreKeys(sessionId,keySetID) insteand of mediaDrm.getKeyRequest(sessionId, schemeInitData.data, schemeInitData.mimeType, MediaDrm.KEY_TYPE_OFFLINE, optionalKeyRequestParameters);
Hi I figured out the download segment part, actually you do not need to change mpd if your segments are all stored under the same dir as the mpd file. I'm able to make clear DASH offline playback happen.
List
for (int i = 0; i < mpd.getPeriodCount(); ++i) { Period period = mpd.getPeriod(i); long duration = mpd.getPeriodDuration(i); for (AdaptationSet as : period.adaptationSets) { for (Representation r : as.representations) { RangedUri initUri = r.getInitializationUri(); String uriString = initUri.getUriString(); results.add(uriString); DashSegmentIndex index = r.getIndex(); RangedUri indexUri = r.getIndexUri(); int firstIndex = index.getFirstSegmentNum(); int lastIndex = index.getLastSegmentNum(duration * 1000); for (int segIndex = firstIndex; segIndex <= lastIndex; ++segIndex) { RangedUri segUri = index.getSegmentUrl(segIndex); if (segUri != null) { String segUriString = segUri.getUriString(); results.add(segUriString); } } } } }
@jiafei1986 How do you kick off the pssh key request process without play the video back after downloading the initialization chunk? Is there an easy way to retrieve pssh box from initialization data and generate pssh key request?
@Matthew-C , actually it is a tricky way i did, i open a player when a download a video to get key, but i wrap the player activity as a progressbar, then i will close the activity once get the drm token,
it looks a normal progress bar to user.
in the StreamingDrmSessionManager , there is a EventListener
` public interface EventListener {
/**
-
Invoked after method provideKeyResponse() to store license locally */ void onDrmKeysLoaded(byte[] data);
/**
- Invoked each time keys are loaded. */ void onDrmKeysLoaded();
/**
- Invoked when a drm error occurs. *
- @param e The corresponding exception. */ void onDrmSessionManagerError(Exception e);
} ` i add on more method void onDrmKeysLoaded(byte[] data); then in the method private void onKeyResponse(Object response) ; call onDrmKeysLoaded(byte[] data) , the data is the keysetId to restore the license
` private void onKeyResponse(Object response) { if (state != STATE_OPENED && state != STATE_OPENED_WITH_KEYS) { // This event is stale. return; }
if (response instanceof Exception) {
onKeysError((Exception) response);
return;
}
try {
final byte[] result=mediaDrm.provideKeyResponse(sessionId, (byte[]) response);
state = STATE_OPENED_WITH_KEYS;
if (eventHandler != null && eventListener != null) {
eventHandler.post(new Runnable() {
@Override
public void run() {
eventListener.onDrmKeysLoaded();
eventListener.onDrmKeysLoaded(result);
}
});
}
} catch (Exception e) {
onKeysError(e);
}
}
`
then in the ExoPlayerController, already implement this EventListener, you can do whatever inside it
Let's track this using https://github.com/google/ExoPlayer/issues/876. Thanks.
Dear All, How to get and store keys for offline DRM videos while playing it using Exoplayer in android. Please suggest and provide sample codes.