use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.
the class ExoPlayerTest method allActivatedTrackSelectionAreReleasedForSinglePeriod.
@Test
public void allActivatedTrackSelectionAreReleasedForSinglePeriod() throws Exception {
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT);
FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
FakeTrackSelector trackSelector = new FakeTrackSelector();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setRenderers(videoRenderer, audioRenderer).setTrackSelector(trackSelector).build().start().blockUntilEnded(TIMEOUT_MS);
List<FakeTrackSelection> createdTrackSelections = trackSelector.getAllTrackSelections();
int numSelectionsEnabled = 0;
// Assert that all tracks selection are disabled at the end of the playback.
for (FakeTrackSelection trackSelection : createdTrackSelections) {
assertThat(trackSelection.isEnabled).isFalse();
numSelectionsEnabled += trackSelection.enableCount;
}
// There are 2 renderers, and track selections are made once (1 period).
assertThat(createdTrackSelections).hasSize(2);
assertThat(numSelectionsEnabled).isEqualTo(2);
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.
the class MappingTrackSelectorTest method selectTracks_multipleMetadataTracks_mappedToDifferentRenderers.
@Test
public void selectTracks_multipleMetadataTracks_mappedToDifferentRenderers() throws ExoPlaybackException {
TrackGroup metadataGroup0 = METADATA_TRACK_GROUP.copyWithId("0");
TrackGroup metadataGroup1 = METADATA_TRACK_GROUP.copyWithId("1");
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, metadataGroup0, metadataGroup1);
RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { VIDEO_CAPABILITIES, METADATA_CAPABILITIES, METADATA_CAPABILITIES };
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(0, VIDEO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(1, metadataGroup0);
trackSelector.assertMappedTrackGroups(2, metadataGroup1);
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.
the class MappingTrackSelectorTest method selectTracks_multipleVideoAndAudioTracks_mappedToSameRenderer.
@Test
public void selectTracks_multipleVideoAndAudioTracks_mappedToSameRenderer() throws ExoPlaybackException {
TrackGroup videoGroup0 = VIDEO_TRACK_GROUP.copyWithId("0");
TrackGroup videoGroup1 = VIDEO_TRACK_GROUP.copyWithId("1");
TrackGroup audioGroup0 = AUDIO_TRACK_GROUP.copyWithId("0");
TrackGroup audioGroup1 = AUDIO_TRACK_GROUP.copyWithId("1");
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
TrackGroupArray trackGroups = new TrackGroupArray(videoGroup0, audioGroup0, audioGroup1, videoGroup1);
RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { VIDEO_CAPABILITIES, AUDIO_CAPABILITIES, VIDEO_CAPABILITIES, AUDIO_CAPABILITIES };
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(0, videoGroup0, videoGroup1);
trackSelector.assertMappedTrackGroups(1, audioGroup0, audioGroup1);
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.
the class TestExoPlayerBuilder method build.
/**
* Builds an {@link ExoPlayer} using the provided values or their defaults.
*/
public ExoPlayer build() {
Assertions.checkNotNull(looper, "TestExoPlayer builder run on a thread without Looper and no Looper specified.");
// Do not update renderersFactory and renderers here, otherwise their getters may
// return different values before and after build() is called, making them confusing.
RenderersFactory playerRenderersFactory = renderersFactory;
if (playerRenderersFactory == null) {
playerRenderersFactory = (eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput) -> renderers != null ? renderers : new Renderer[] { new FakeVideoRenderer(eventHandler, videoRendererEventListener), new FakeAudioRenderer(eventHandler, audioRendererEventListener) };
}
ExoPlayer.Builder builder = new ExoPlayer.Builder(context, playerRenderersFactory).setTrackSelector(trackSelector).setLoadControl(loadControl).setBandwidthMeter(bandwidthMeter).setAnalyticsCollector(new DefaultAnalyticsCollector(clock)).setClock(clock).setUseLazyPreparation(useLazyPreparation).setLooper(looper).setSeekBackIncrementMs(seekBackIncrementMs).setSeekForwardIncrementMs(seekForwardIncrementMs);
if (mediaSourceFactory != null) {
builder.setMediaSourceFactory(mediaSourceFactory);
}
return builder.build();
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project AntennaPod by AntennaPod.
the class ExoPlayerWrapper method createPlayer.
private void createPlayer() {
DefaultLoadControl.Builder loadControl = new DefaultLoadControl.Builder();
loadControl.setBufferDurationsMs(30000, 120000, DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS, DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS);
loadControl.setBackBuffer(UserPreferences.getRewindSecs() * 1000 + 500, true);
trackSelector = new DefaultTrackSelector(context);
exoPlayer = new SimpleExoPlayer.Builder(context, new DefaultRenderersFactory(context)).setTrackSelector(trackSelector).setLoadControl(loadControl.build()).build();
exoPlayer.setSeekParameters(SeekParameters.EXACT);
exoPlayer.addListener(new Player.Listener() {
@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
if (audioCompletionListener != null && playbackState == Player.STATE_ENDED) {
audioCompletionListener.onCompletion(null);
} else if (infoListener != null && playbackState == Player.STATE_BUFFERING) {
infoListener.onInfo(null, android.media.MediaPlayer.MEDIA_INFO_BUFFERING_START, 0);
} else if (infoListener != null) {
infoListener.onInfo(null, android.media.MediaPlayer.MEDIA_INFO_BUFFERING_END, 0);
}
}
@Override
public void onPlayerError(@NonNull ExoPlaybackException error) {
if (audioErrorListener != null) {
if (NetworkUtils.wasDownloadBlocked(error)) {
audioErrorListener.accept(context.getString(R.string.download_error_blocked));
} else {
Throwable cause = error.getCause();
if (cause instanceof HttpDataSource.HttpDataSourceException) {
if (cause.getCause() != null) {
cause = cause.getCause();
}
}
if (cause != null && "Source error".equals(cause.getMessage())) {
cause = cause.getCause();
}
audioErrorListener.accept(cause != null ? cause.getMessage() : error.getMessage());
}
}
}
@Override
public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, @Player.DiscontinuityReason int reason) {
if (audioSeekCompleteListener != null && reason == Player.DISCONTINUITY_REASON_SEEK) {
audioSeekCompleteListener.onSeekComplete(null);
}
}
});
}
Aggregations