在AndroidManifest.xml文件中添加以下权限:
使用以下代码检查设备的安全级别是否符合要求:
MediaDrm mediaDrm = new MediaDrm(WIDEVINE_UUID);
String securityLevel = mediaDrm.getPropertyString("securityLevel");
if (securityLevel.equals("L1")) {
// Device is Widevine L1 certified
} else {
// Device is NOT Widevine L1 certified
}
使用以下代码检查设备是否处于compliant状态:
MediaDrm mediaDrm = new MediaDrm(WIDEVINE_UUID);
String provider = mediaDrm.getPropertyString("vendor");
if (provider.equals("widevine")) {
String drmVersion = mediaDrm.getPropertyString("version");
int level = Integer.parseInt(drmVersion.split("\\.")[0]);
if (level >= 6) {
String status = mediaDrm.getPropertyString("com.widevine.alpha.drm.info");
if (status.contains("Compliant")) {
// Device is compliant
} else {
// Device is NOT compliant
}
}
}
使用以下代码检查设备是否安装了正确的Widevine CDM:
private boolean isWidevineCDMInstalled(Context context) {
PackageManager manager = context.getPackageManager();
List apps = manager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo app : apps) {
if (app.packageName.equals("com.google.android.exoplayer2.demo")) {
try {
PackageInfo packageInfo = manager.getPackageInfo(app.packageName, PackageManager.GET_ACTIVITIES);
String path = packageInfo.applicationInfo.dataDir + "/widevine";
File file = new File(path);
if (file.exists()) {
// Widevine CDM is installed
return true;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
}
return false;
}
如果Widevine CDM未正确安装,请按照以下步骤解决问题:
implementation 'com.google.android.exoplayer:exoplayer-core:[version_number]'
Default