Search in sources :

Example 1 with DrmSessionEventListener

use of com.google.android.exoplayer2.drm.DrmSessionEventListener in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onDrmSessionAcquired.

// DrmSessionEventListener implementation.
@Override
// Calls deprecated listener method.
@SuppressWarnings("deprecation")
public final void onDrmSessionAcquired(int windowIndex, @Nullable MediaPeriodId mediaPeriodId, @DrmSession.State int state) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_DRM_SESSION_ACQUIRED, listener -> {
        listener.onDrmSessionAcquired(eventTime);
        listener.onDrmSessionAcquired(eventTime, state);
    });
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 2 with DrmSessionEventListener

use of com.google.android.exoplayer2.drm.DrmSessionEventListener in project ExoPlayer by google.

the class DefaultDrmSessionManagerTest method preacquireSession_loadsKeysBeforeFullAcquisition.

@Test(timeout = 10_000)
public void preacquireSession_loadsKeysBeforeFullAcquisition() throws Exception {
    AtomicInteger keyLoadCount = new AtomicInteger(0);
    DrmSessionEventListener.EventDispatcher eventDispatcher = new DrmSessionEventListener.EventDispatcher();
    eventDispatcher.addEventListener(Util.createHandlerForCurrentLooper(), new DrmSessionEventListener() {

        @Override
        public void onDrmKeysLoaded(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId) {
            keyLoadCount.incrementAndGet();
        }
    });
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm()).setSessionKeepaliveMs(C.TIME_UNSET).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSessionReference sessionReference = drmSessionManager.preacquireSession(eventDispatcher, FORMAT_WITH_DRM_INIT_DATA);
    // STATE_OPENED_WITH_KEYS.
    while (keyLoadCount.get() == 0) {
        // Allow the key response to be handled.
        ShadowLooper.idleMainLooper();
    }
    DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    // Without idling the main/playback looper, we assert the session is already in OPENED_WITH_KEYS
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    assertThat(keyLoadCount.get()).isEqualTo(1);
    // After releasing our concrete session reference, the session is held open by the pre-acquired
    // reference.
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    // Releasing the pre-acquired reference allows the session to be fully released.
    sessionReference.release();
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) DrmSessionReference(com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference) MediaSource(com.google.android.exoplayer2.source.MediaSource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)1 DrmSessionReference (com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 FakeExoMediaDrm (com.google.android.exoplayer2.testutil.FakeExoMediaDrm)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1