com.google.android.exoplayer2.drm.FrameworkMediaDrm Java Examples

The following examples show how to use com.google.android.exoplayer2.drm.FrameworkMediaDrm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(UUID uuid,
																	   String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {
	if (Util.SDK_INT < 18) {
		return null;
	}
	HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
																buildHttpDataSourceFactory(false));
	if (keyRequestPropertiesArray != null) {
		for (int i = 0; i < keyRequestPropertiesArray.length - 1; i += 2) {
			drmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i],
											  keyRequestPropertiesArray[i + 1]);
		}
	}
	return new DefaultDrmSessionManager<FrameworkMediaCrypto>(uuid,
										  FrameworkMediaDrm.newInstance(uuid), drmCallback, null, mainHandler, eventLogger);
}
 
Example #2
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * Generates the {@link DrmSessionManager} to use with the {@link RendererProvider}. This will
 * return null on API's &lt; {@value Build.VERSION_CODES#JELLY_BEAN_MR2}
 *
 * @return The {@link DrmSessionManager} to use or <code>null</code>
 */
@Nullable
protected DrmSessionManager<FrameworkMediaCrypto> generateDrmSessionManager() {
    // DRM is only supported on API 18 + in the ExoPlayer
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return null;
    }

    // Widevine will capture the majority of use cases however playready is supported on all AndroidTV devices
    UUID uuid = C.WIDEVINE_UUID;

    try {
        DefaultDrmSessionManager<FrameworkMediaCrypto> sessionManager = new DefaultDrmSessionManager<>(uuid, FrameworkMediaDrm.newInstance(uuid), new DelegatedMediaDrmCallback(), null);
        sessionManager.addListener(mainHandler, capabilitiesListener);

        return sessionManager;
    } catch (Exception e) {
        Log.d(TAG, "Unable to create a DrmSessionManager due to an exception", e);
        return null;
    }
}
 
Example #3
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
private DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(UUID uuid,
                                                                       String licenseUrl, Map<String, String> keyRequestProperties) throws UnsupportedDrmException {
    if (Util.SDK_INT < 18) {
        return null;
    }
    HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
            buildHttpDataSourceFactory(false), keyRequestProperties);
    return new DefaultDrmSessionManager<>(uuid,
            FrameworkMediaDrm.newInstance(uuid), drmCallback, null, mainHandler, eventLogger);
}
 
Example #4
Source File: FrameworkMediaDrmCreator.java    From no-player with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.PreserveStackTrace")  // We just unwrap the exception because we don't care about the UnsupportedDrmException itself
FrameworkMediaDrm create(UUID uuid) {
    try {
        return FrameworkMediaDrm.newInstance(uuid);
    } catch (UnsupportedDrmException e) {
        throw new FrameworkMediaDrmException(e.getMessage(), e.getCause());
    }
}
 
Example #5
Source File: StreamingDrmSessionCreator.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public DrmSessionManager<FrameworkMediaCrypto> create(DefaultDrmSessionEventListener eventListener) {
    FrameworkMediaDrm frameworkMediaDrm = frameworkMediaDrmCreator.create(WIDEVINE_MODULAR_UUID);

    DefaultDrmSessionManager<FrameworkMediaCrypto> defaultDrmSessionManager = new DefaultDrmSessionManager<>(
            WIDEVINE_MODULAR_UUID,
            frameworkMediaDrm,
            mediaDrmCallback,
            NO_OPTIONAL_PARAMETERS
    );
    defaultDrmSessionManager.removeListener(eventListener);
    defaultDrmSessionManager.addListener(handler, eventListener);

    return defaultDrmSessionManager;
}
 
Example #6
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 4 votes vote down vote up
private DrmSessionManager<FrameworkMediaCrypto> buildOfflineDrmSessionManager(UUID uuid,
                                                                              String licenseUrl, Map<String, String> keyRequestProperties) throws UnsupportedDrmException, IOException, DrmSession.DrmSessionException, InterruptedException {
    if (Util.SDK_INT < 18) {
        return null;
    }

    customDrmCallback = new CustomDrmCallback(
            DemoApplication.getAppInstance().buildHttpDataSourceFactory(new DefaultBandwidthMeter()),
            licenseUrl
    );

    DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = new DefaultDrmSessionManager<>(uuid,
            FrameworkMediaDrm.newInstance(uuid), customDrmCallback, null, mainHandler, eventLogger);

    String offlineAssetKeyIdStr = DemoApplication.getAppInstance().
            getSharedPreferences().getString(DemoApplication.KEY_OFFLINE_OFFSET_ID,DemoApplication.EMPTY);
    byte[] offlineAssetKeyId = Base64.decode(offlineAssetKeyIdStr, Base64.DEFAULT);
    this.offlineLicenseHelper = OfflineLicenseHelper.newWidevineInstance(customDrmCallback, null);
    Pair<Long, Long> remainingSecPair = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineAssetKeyId);
    Log.e(TAG," License remaining Play time : "+remainingSecPair.first+", Purchase time : "+remainingSecPair.second);
    if(DemoApplication.EMPTY.equals(offlineAssetKeyIdStr) || ( remainingSecPair.first == 0 || remainingSecPair.second == 0)) {
        String path = getIntent().getStringExtra(EXTRA_OFFLINE_URI);
        File file = getUriForManifest(path);
        Uri uri = Uri.fromFile(file);
        InputStream is = new FileInputStream(file);
        Log.e(TAG, "will start download now");
        offlineAssetKeyId = offlineLicenseHelper.download(
                DemoApplication.getAppInstance().buildHttpDataSourceFactory(new DefaultBandwidthMeter()).createDataSource(),
                new DashManifestParser().parse(uri, is));
        Pair<Long, Long> p = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineAssetKeyId);
        Log.e(TAG, "download done : " + p.toString());

        SharedPreferences sharedPreferences = DemoApplication.getAppInstance().getSharedPreferences();
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(DemoApplication.KEY_OFFLINE_OFFSET_ID,
                Base64.encodeToString(offlineAssetKeyId, Base64.DEFAULT));
        editor.commit();
    }


    drmSessionManager.setMode(DefaultDrmSessionManager.MODE_QUERY,offlineAssetKeyId);
    return drmSessionManager;
}