use of androidx.media3.exoplayer.upstream.Loader in project media by androidx.
the class DashMediaSource method prepareSourceInternal.
@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
this.mediaTransferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */
Looper.myLooper(), getPlayerId());
if (sideloadedManifest) {
processManifest(false);
} else {
dataSource = manifestDataSourceFactory.createDataSource();
loader = new Loader("DashMediaSource");
handler = Util.createHandlerForCurrentLooper();
startLoadingManifest();
}
}
use of androidx.media3.exoplayer.upstream.Loader 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.upstream.Loader in project media by androidx.
the class ImaServerSideAdInsertionMediaSource method prepareSourceInternal.
@Override
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
mainHandler.post(() -> assertSingleInstanceInPlaylist(checkNotNull(player)));
super.prepareSourceInternal(mediaTransferListener);
if (loader == null) {
Loader loader = new Loader("ImaServerSideAdInsertionMediaSource");
player.addListener(componentListener);
StreamManagerLoadable streamManagerLoadable = new StreamManagerLoadable(sdkAdsLoader, streamRequest, streamPlayer, applicationAdErrorListener, loadVideoTimeoutMs);
loader.startLoading(streamManagerLoadable, new StreamManagerLoadableCallback(), /* defaultMinRetryCount= */
0);
this.loader = loader;
}
}
use of androidx.media3.exoplayer.upstream.Loader in project media by androidx.
the class AdsMediaSourceTest method setUp.
@Before
public void setUp() {
// Set up content and ad media sources, passing a null timeline so tests can simulate setting it
// later.
contentMediaSource = new FakeMediaSource(/* timeline= */
null);
prerollAdMediaSource = new FakeMediaSource(/* timeline= */
null);
MediaSource.Factory adMediaSourceFactory = mock(MediaSource.Factory.class);
when(adMediaSourceFactory.createMediaSource(any(MediaItem.class))).thenReturn(prerollAdMediaSource);
// Prepare the AdsMediaSource and capture its ads loader listener.
AdsLoader mockAdsLoader = mock(AdsLoader.class);
AdViewProvider mockAdViewProvider = mock(AdViewProvider.class);
ArgumentCaptor<EventListener> eventListenerArgumentCaptor = ArgumentCaptor.forClass(AdsLoader.EventListener.class);
adsMediaSource = new AdsMediaSource(contentMediaSource, TEST_ADS_DATA_SPEC, TEST_ADS_ID, adMediaSourceFactory, mockAdsLoader, mockAdViewProvider);
adsMediaSource.prepareSource(mockMediaSourceCaller, /* mediaTransferListener= */
null, PlayerId.UNSET);
shadowOf(Looper.getMainLooper()).idle();
verify(mockAdsLoader).start(eq(adsMediaSource), eq(TEST_ADS_DATA_SPEC), eq(TEST_ADS_ID), eq(mockAdViewProvider), eventListenerArgumentCaptor.capture());
// Simulate loading a preroll ad.
AdsLoader.EventListener adsLoaderEventListener = eventListenerArgumentCaptor.getValue();
adsLoaderEventListener.onAdPlaybackState(AD_PLAYBACK_STATE);
shadowOf(Looper.getMainLooper()).idle();
}
use of androidx.media3.exoplayer.upstream.Loader in project media by androidx.
the class ExoPlayerTest method loading_withLargeAllocationCausingOom_playsRemainingMediaAndThenThrows.
@Test
public void loading_withLargeAllocationCausingOom_playsRemainingMediaAndThenThrows() {
Loader.Loadable loadable = new Loader.Loadable() {
@SuppressWarnings("UnusedVariable")
@Override
public void load() throws IOException {
// This test needs the allocation to cause an OOM.
@SuppressWarnings("unused") byte[] largeBuffer = new byte[Integer.MAX_VALUE];
}
@Override
public void cancelLoad() {
}
};
// Create 3 samples without end of stream signal to test that all 3 samples are
// still played before the sample stream exception is thrown.
FakeSampleStreamItem sample = oneByteSample(TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, C.BUFFER_FLAG_KEY_FRAME);
FakeMediaPeriod.TrackDataFactory threeSamplesWithoutEos = (format, mediaPeriodId) -> ImmutableList.of(sample, sample, sample);
MediaSource largeBufferAllocatingMediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {
@Override
protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
return new FakeMediaPeriod(trackGroupArray, allocator, threeSamplesWithoutEos, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
false) {
private final Loader loader = new Loader("ExoPlayerTest");
@Override
public boolean continueLoading(long positionUs) {
super.continueLoading(positionUs);
if (!loader.isLoading()) {
loader.startLoading(loadable, new FakeLoaderCallback(), /* defaultMinRetryCount= */
1);
}
return true;
}
@Override
protected FakeSampleStream createSampleStream(Allocator allocator, @Nullable MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, Format initialFormat, List<FakeSampleStreamItem> fakeSampleStreamItems) {
return new FakeSampleStream(allocator, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, initialFormat, fakeSampleStreamItems) {
@Override
public void maybeThrowError() throws IOException {
loader.maybeThrowError();
}
};
}
};
}
};
FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(largeBufferAllocatingMediaSource).setRenderers(renderer).build();
ExoPlaybackException exception = assertThrows(ExoPlaybackException.class, () -> testRunner.start().blockUntilEnded(TIMEOUT_MS));
assertThat(exception.type).isEqualTo(ExoPlaybackException.TYPE_SOURCE);
assertThat(exception.getSourceException()).isInstanceOf(Loader.UnexpectedLoaderException.class);
assertThat(exception.getSourceException().getCause()).isInstanceOf(OutOfMemoryError.class);
assertThat(renderer.sampleBufferReadCount).isEqualTo(3);
}
Aggregations