use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.
the class OfflineLicenseHelper method blockingKeyRequest.
private byte[] blockingKeyRequest(@Mode int licenseMode, @Nullable byte[] offlineLicenseKeySetId, Format format) throws DrmSessionException {
drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId, format);
DrmSessionException error = drmSession.getError();
byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
drmSession.release(eventDispatcher);
drmSessionManager.release();
if (error != null) {
throw error;
}
return Assertions.checkNotNull(keySetId);
}
use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.
the class DefaultHlsPlaylistTracker method start.
// HlsPlaylistTracker implementation.
@Override
public void start(Uri initialPlaylistUri, EventDispatcher eventDispatcher, PrimaryPlaylistListener primaryPlaylistListener) {
this.playlistRefreshHandler = Util.createHandlerForCurrentLooper();
this.eventDispatcher = eventDispatcher;
this.primaryPlaylistListener = primaryPlaylistListener;
ParsingLoadable<HlsPlaylist> multivariantPlaylistLoadable = new ParsingLoadable<>(dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST), initialPlaylistUri, C.DATA_TYPE_MANIFEST, playlistParserFactory.createPlaylistParser());
Assertions.checkState(initialPlaylistLoader == null);
initialPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MultivariantPlaylist");
long elapsedRealtime = initialPlaylistLoader.startLoading(multivariantPlaylistLoadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(multivariantPlaylistLoadable.type));
eventDispatcher.loadStarted(new LoadEventInfo(multivariantPlaylistLoadable.loadTaskId, multivariantPlaylistLoadable.dataSpec, elapsedRealtime), multivariantPlaylistLoadable.type);
}
use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.
the class FakeMediaSource method finishSourcePreparation.
private void finishSourcePreparation(boolean sendManifestLoadEvents) {
refreshSourceInfo(Assertions.checkStateNotNull(timeline));
if (!timeline.isEmpty() && sendManifestLoadEvents) {
MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MANIFEST, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */
null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
null, /* mediaStartTimeMs= */
C.TIME_UNSET, /* mediaEndTimeMs = */
C.TIME_UNSET);
long elapsedRealTimeMs = SystemClock.elapsedRealtime();
MediaSourceEventListener.EventDispatcher eventDispatcher = createEventDispatcher(/* mediaPeriodId= */
null);
long loadTaskId = LoadEventInfo.getNewId();
eventDispatcher.loadStarted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
0, /* bytesLoaded= */
0), mediaLoadData);
eventDispatcher.loadCompleted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
0, /* bytesLoaded= */
MANIFEST_LOAD_BYTES), mediaLoadData);
}
}
use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.
the class DefaultDrmSessionManager method acquireSession.
// Must be called on the playback thread.
@Nullable
private DrmSession acquireSession(Looper playbackLooper, @Nullable DrmSessionEventListener.EventDispatcher eventDispatcher, Format format, boolean shouldReleasePreacquiredSessionsBeforeRetrying) {
maybeCreateMediaDrmHandler(playbackLooper);
if (format.drmInitData == null) {
// Content is not encrypted.
return maybeAcquirePlaceholderSession(MimeTypes.getTrackType(format.sampleMimeType), shouldReleasePreacquiredSessionsBeforeRetrying);
}
@Nullable List<SchemeData> schemeDatas = null;
if (offlineLicenseKeySetId == null) {
schemeDatas = getSchemeDatas(checkNotNull(format.drmInitData), uuid, false);
if (schemeDatas.isEmpty()) {
final MissingSchemeDataException error = new MissingSchemeDataException(uuid);
Log.e(TAG, "DRM error", error);
if (eventDispatcher != null) {
eventDispatcher.drmSessionManagerError(error);
}
return new ErrorStateDrmSession(new DrmSessionException(error, PlaybackException.ERROR_CODE_DRM_CONTENT_ERROR));
}
}
@Nullable DefaultDrmSession session;
if (!multiSession) {
session = noMultiSessionDrmSession;
} else {
// Only use an existing session if it has matching init data.
session = null;
for (DefaultDrmSession existingSession : sessions) {
if (Util.areEqual(existingSession.schemeDatas, schemeDatas)) {
session = existingSession;
break;
}
}
}
if (session == null) {
// Create a new session.
session = createAndAcquireSessionWithRetry(schemeDatas, /* isPlaceholderSession= */
false, eventDispatcher, shouldReleasePreacquiredSessionsBeforeRetrying);
if (!multiSession) {
noMultiSessionDrmSession = session;
}
sessions.add(session);
} else {
session.acquire(eventDispatcher);
}
return session;
}
use of androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher in project media by androidx.
the class DefaultDrmSessionManagerTest method managerRelease_keepaliveDisabled_doesntReleaseAnySessions.
@Test(timeout = 10_000)
public void managerRelease_keepaliveDisabled_doesntReleaseAnySessions() throws Exception {
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);
DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
null, FORMAT_WITH_DRM_INIT_DATA));
waitForOpenedWithKeys(drmSession);
assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
// Release the manager, the session should still be open (though it's unusable because
// the underlying ExoMediaDrm is released).
drmSessionManager.release();
assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
}
Aggregations