问题
I am trying to play the .MPD file, which is using
DRMSchema : clearKey
For playing it i am creating a DefaultDrmSessionManager in the following way
String keyString = "{\"keys\":[{\"kty\":\"oct\",\"k\":\"y1QQhMmXMa70__dFAMEurQ\n" +
" \",\"kid\":\"bXbyXLF_Xha46u9rv1gtjg\n" +
" \"},{\"kty\":\"oct\",\"k\":\"pGMaFTpEPfnu0FkwQ9t1GQ\n" +
" \",\"kid\":\"88XgNh5mVLKPgEnHeLI5Rg\n" +
" \"}],'type':\"temporary\"}";
LogMgr.i("DRMCallback JSON : " + keyString);
drmCallback = new LocalMediaDrmCallback(keyString.getBytes());
mediaDrm = FrameworkMediaDrm.newInstance(uuid);
DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, drmCallback, null, multiSession);
After that, when i am trying to use this DefaultDrmSessionManager for playing the video, i am getting ExoPlayerImplInternal: Playback error, i am attaching the Log for reference.
E/ExoPlayerImplInternal: **Playback error**.
com.google.android.exoplayer2.ExoPlaybackException
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:780)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:583)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: android.media.MediaCodec$CryptoException: **Crypto key not available**
at android.media.MediaCodec.native_queueSecureInputBuffer(Native Method)
at android.media.MediaCodec.queueSecureInputBuffer(MediaCodec.java:2547)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:771)
Please guide me, what i am doing wrong
回答1:
Looking at the length of the key string, the most likely problem is that the key has not been base64URL encoded in the call to LocalMediaDrmCallback.
An AES 128-bit key will be:
- 32 characters as a hex key
- 24 characters when base64 encoded
Assuming that a4631a153a443df9eed0593043db7519 is the key in hex format then you need to convert it (and the keyID also) to base64 and then pass them this way to LocalMediaDrmCallback.
Using one of the common online convertors you can see this would give:
- hex key: a4631a153a443df9eed0593043db7519
- base64 encoded pGMaFTpEPfnu0FkwQ9t1GQ==
You can see an example of doing this programmatically also in this GitHub issue answer: https://github.com/google/ExoPlayer/issues/3856#issuecomment-366197586
回答2:
It is working fine after removing \n from the keyString.. :)
来源:https://stackoverflow.com/questions/53426119/playback-error-on-using-clearkey-drm-schema-in-exoplayer-2-android