use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.
the class SingleSampleMediaPeriod method onLoadError.
@Override
public LoadErrorAction onLoadError(SourceLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
StatsDataSource dataSource = loadable.dataSource;
LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, dataSource.getLastOpenedUri(), dataSource.getLastResponseHeaders(), elapsedRealtimeMs, loadDurationMs, dataSource.getBytesRead());
MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
null, /* mediaStartTimeMs= */
0, Util.usToMs(durationUs));
long retryDelay = loadErrorHandlingPolicy.getRetryDelayMsFor(new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount));
boolean errorCanBePropagated = retryDelay == C.TIME_UNSET || errorCount >= loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA);
LoadErrorAction action;
if (treatLoadErrorsAsEndOfStream && errorCanBePropagated) {
Log.w(TAG, "Loading failed, treating as end-of-stream.", error);
loadingFinished = true;
action = Loader.DONT_RETRY;
} else {
action = retryDelay != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
false, retryDelay) : Loader.DONT_RETRY_FATAL;
}
boolean wasCanceled = !action.isRetry();
eventDispatcher.loadError(loadEventInfo, C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
null, /* mediaStartTimeUs= */
0, durationUs, error, wasCanceled);
if (wasCanceled) {
loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
}
return action;
}
use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.
the class CacheDataSourceTest method switchToCacheSourceWithNonBlockingCacheDataSource.
@Test
public void switchToCacheSourceWithNonBlockingCacheDataSource() throws Exception {
// Create a fake data source with a 1 MB default data.
FakeDataSource upstream = new FakeDataSource();
FakeData fakeData = upstream.getDataSet().newDefaultData().appendReadData(1024 * 1024 - 1);
// Insert an action just before the end of the data to fail the test if reading from upstream
// reaches end of the data.
fakeData.appendReadAction(() -> fail("Read from upstream shouldn't reach to the end of the data.")).appendReadData(1);
// Lock the content on the cache.
CacheSpan cacheSpan = cache.startReadWriteNonBlocking(defaultCacheKey, 0, C.LENGTH_UNSET);
assertThat(cacheSpan).isNotNull();
assertThat(cacheSpan.isHoleSpan()).isTrue();
// Create non blocking CacheDataSource.
CacheDataSource cacheDataSource = new CacheDataSource(cache, upstream, 0);
// Open source and read some data from upstream without writing to cache as the data is locked.
cacheDataSource.open(unboundedDataSpec);
byte[] buffer = new byte[1024];
cacheDataSource.read(buffer, 0, buffer.length);
// Unlock the span.
cache.releaseHoleSpan(cacheSpan);
assertCacheEmpty(cache);
// Cache the data. Although we use another FakeDataSource instance, it shouldn't matter.
FakeDataSource upstream2 = new FakeDataSource(new FakeDataSource().getDataSet().newDefaultData().appendReadData(1024 * 1024).endData());
CacheWriter cacheWriter = new CacheWriter(new CacheDataSource(cache, upstream2), unboundedDataSpec, /* temporaryBuffer= */
null, /* progressListener= */
null);
cacheWriter.cache();
// Read the rest of the data.
DataSourceUtil.readToEnd(cacheDataSource);
cacheDataSource.close();
}
use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.
the class ExoPlayerTest method setPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndIsMasked.
@Test
public void setPlaybackSpeedConsecutivelyNotifiesListenerForEveryChangeOnceAndIsMasked() throws Exception {
List<Float> maskedPlaybackSpeeds = new ArrayList<>();
Action getPlaybackSpeedAction = new Action("getPlaybackSpeed", /* description= */
null) {
@Override
protected void doActionImpl(ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) {
maskedPlaybackSpeeds.add(player.getPlaybackParameters().speed);
}
};
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.1f)).apply(getPlaybackSpeedAction).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.2f)).apply(getPlaybackSpeedAction).setPlaybackParameters(new PlaybackParameters(/* speed= */
1.3f)).apply(getPlaybackSpeedAction).play().build();
List<Float> reportedPlaybackSpeeds = new ArrayList<>();
Player.Listener listener = new Player.Listener() {
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
reportedPlaybackSpeeds.add(playbackParameters.speed);
}
};
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(reportedPlaybackSpeeds).containsExactly(1.1f, 1.2f, 1.3f).inOrder();
assertThat(maskedPlaybackSpeeds).isEqualTo(reportedPlaybackSpeeds);
}
use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.
the class ExoPlayerTest method timelineUpdateInMultiWindowMediaSource_removingPeriod_withUnpreparedMaskingMediaPeriod_doesNotThrow.
@Test
public void timelineUpdateInMultiWindowMediaSource_removingPeriod_withUnpreparedMaskingMediaPeriod_doesNotThrow() throws Exception {
TimelineWindowDefinition window1 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
1);
TimelineWindowDefinition window2 = new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
2);
FakeMediaSource mediaSource = new FakeMediaSource(/* timeline= */
null);
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).waitForPendingPlayerCommands().executeRunnable(() -> mediaSource.setNewSourceInfo(new FakeTimeline(window1, window2))).waitForTimelineChanged().executeRunnable(() -> mediaSource.setNewSourceInfo(new FakeTimeline(window2))).waitForTimelineChanged().stop().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
// Assertion is to not throw while running the action schedule above.
}
use of com.google.android.exoplayer2.testutil.Action in project ExoPlayer by google.
the class DownloadServiceDashTest method downloadKeys.
private void downloadKeys(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys);
DownloadRequest action = new DownloadRequest.Builder(TEST_ID, TEST_MPD_URI).setMimeType(MimeTypes.APPLICATION_MPD).setStreamKeys(keysList).build();
testThread.runOnMainThread(() -> {
Intent startIntent = DownloadService.buildAddDownloadIntent(context, DownloadService.class, action, /* foreground= */
false);
dashDownloadService.onStartCommand(startIntent, 0, 0);
});
}
Aggregations