我正在尝试播放受DRM保护的流URL,并出现以下错误。
Caused by: com.google.android.exoplayer2.drm.DrmSession$DrmSessionException: java.io.IOException: Error during license acquisition
at com.google.android.exoplayer2.drm.DefaultDrmSession.onError(DefaultDrmSession.java:422)
at com.google.android.exoplayer2.drm.DefaultDrmSession.onKeysError(DefaultDrmSession.java:417)
at com.google.android.exoplayer2.drm.DefaultDrmSession.onKeyResponse(DefaultDrmSession.java:379)
at com.google.android.exoplayer2.drm.DefaultDrmSession.access$100(DefaultDrmSession.java:41)
at com.google.android.exoplayer2.drm.DefaultDrmSession$PostResponseHandler.handleMessage(DefaultDrmSession.java:472)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.io.IOException: Error during license acquisition
at com.osolutions.otv.movie.exoplayer.ExoplayerActivity$1.executeKeyRequest(ExoplayerActivity.java:216)
at com.google.android.exoplayer2.drm.DefaultDrmSession$PostRequestHandler.handleMessage(DefaultDrmSession.java:503)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 400
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:211)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.checkOpened(DataSourceInputStream.java:102)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.read(DataSourceInputStream.java:82)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.read(DataSourceInputStream.java:76)
at com.google.android.exoplayer2.util.Util.toByteArray(Util.java:128)
at com.osolutions.otv.movie.exoplayer.ExoplayerActivity.executePost(ExoplayerActivity.java:253)
at com.osolutions.otv.movie.exoplayer.ExoplayerActivity.access$000(ExoplayerActivity.java:77)
at com.osolutions.otv.movie.exoplayer.ExoplayerActivity$1.executeKeyRequest(ExoplayerActivity.java:212)
at com.google.android.exoplayer2.drm.DefaultDrmSession$PostRequestHandler.handleMessage(DefaultDrmSession.java:503)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
我将MediaDrmCallback用作:
MediaDrmCallback mediaDrmCallback = new MediaDrmCallback() {
@Override
public byte[] executeProvisionRequest(UUID uuid, ExoMediaDrm.ProvisionRequest request) throws Exception {
String url = request.getDefaultUrl() + "&signedRequest=" + new String(request.getData());
return executePost(url, null, null);
//return executePost(dataSourceFactory, url, null, null);
}
@Override
public byte[] executeKeyRequest(UUID uuid, ExoMediaDrm.KeyRequest request) throws Exception {
//Holder for additional req parameters, as per custom implementation
Map<String, String> requestProperties = new HashMap<>();
Uri.Builder builder = Uri.parse(DRM_LICENSE_URL).buildUpon();
// Set content type for Widevine
requestProperties.put("Content-Type", "text/xml");
Uri uri = builder.build();
try {
return executePost(uri.toString(), request.getData(), requestProperties);
} catch (FileNotFoundException e) {
throw new IOException("License not found");
} catch (IOException e) {
throw new IOException("Error during license acquisition", e);
}
}
};
如果我将以下内容替换为executeKeyRequest方法,则该方法有效,并且在这段时间内,我只能播放视频9秒钟。
public byte[] executeKeyRequest(UUID uuid, ExoMediaDrm.KeyRequest request) throws Exception {
try {
flag = false;
String payload = Base64.encodeToString(request.getData(), Base64.DEFAULT);
LogCS.e("payload", payload.trim().replaceAll("\n", ""));
DRMLicensePresenterImpl drmLicensePresenter = new DRMLicensePresenterImpl(ExoplayerActivity.this, ExoplayerActivity.this, payload.trim().replaceAll("\n", ""), ticketToStream);
drmLicensePresenter.getDRMLicenseDetail(UrlUtil.getAltBalajiUrl(ExoplayerActivity.this, UrlUtil.DRM_LICENSE));
} catch (Exception e) {
e.printStackTrace();
}
LogCS.e("license is" + count++ + "----", license);
// get license
return Base64.decode(license, Base64.DEFAULT);
}
我真的很麻烦。任何帮助将不胜感激。