Search in sources :

Example 16 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class MappingTrackSelectorTest method selectTracks_audioAndVideo_reverseOrderToRenderers_mappedToCorrectRenderer.

@Test
public void selectTracks_audioAndVideo_reverseOrderToRenderers_mappedToCorrectRenderer() throws ExoPlaybackException {
    FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
    TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
    RendererCapabilities[] reverseOrderRendererCapabilities = new RendererCapabilities[] { AUDIO_CAPABILITIES, VIDEO_CAPABILITIES };
    trackSelector.selectTracks(reverseOrderRendererCapabilities, trackGroups, periodId, TIMELINE);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    0, AUDIO_TRACK_GROUP);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    1, VIDEO_TRACK_GROUP);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 17 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class MediaPeriodQueueTest method setUp.

@Before
public void setUp() {
    AnalyticsCollector analyticsCollector = new DefaultAnalyticsCollector(Clock.DEFAULT);
    analyticsCollector.setPlayer(new ExoPlayer.Builder(ApplicationProvider.getApplicationContext()).build(), Looper.getMainLooper());
    mediaPeriodQueue = new MediaPeriodQueue(analyticsCollector, new Handler(Looper.getMainLooper()));
    mediaSourceList = new MediaSourceList(mock(MediaSourceList.MediaSourceListInfoRefreshListener.class), analyticsCollector, new Handler(Looper.getMainLooper()), PlayerId.UNSET);
    rendererCapabilities = new RendererCapabilities[0];
    trackSelector = mock(TrackSelector.class);
    allocator = mock(Allocator.class);
}
Also used : Allocator(com.google.android.exoplayer2.upstream.Allocator) DefaultAnalyticsCollector(com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector) AnalyticsCollector(com.google.android.exoplayer2.analytics.AnalyticsCollector) TrackSelector(com.google.android.exoplayer2.trackselection.TrackSelector) Handler(android.os.Handler) DefaultAnalyticsCollector(com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector) Before(org.junit.Before)

Example 18 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector 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);
}
Also used : Action(com.google.android.exoplayer2.testutil.Action) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) ArrayList(java.util.ArrayList) Surface(android.view.Surface) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) Listener(com.google.android.exoplayer2.Player.Listener) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 19 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class ExoPlayerTest method allActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreRemade.

@Test
public void allActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreRemade() 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);
    final FakeTrackSelector trackSelector = new FakeTrackSelector();
    ActionSchedule disableTrackAction = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).disableRenderer(0).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setRenderers(videoRenderer, audioRenderer).setTrackSelector(trackSelector).setActionSchedule(disableTrackAction).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 twice. The second time one renderer is
    // disabled, so only one out of the two track selections is enabled.
    assertThat(createdTrackSelections).hasSize(3);
    assertThat(numSelectionsEnabled).isEqualTo(3);
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeTrackSelection(com.google.android.exoplayer2.testutil.FakeTrackSelection) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTrackSelector(com.google.android.exoplayer2.testutil.FakeTrackSelector) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 20 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class DashPlaybackTest method webvttInMp4.

// https://github.com/google/ExoPlayer/issues/7985
@Test
@Ignore("Disabled until subtitles are reliably asserted in robolectric tests [internal b/174661563].")
public void webvttInMp4() throws Exception {
    Context applicationContext = ApplicationProvider.getApplicationContext();
    CapturingRenderersFactory capturingRenderersFactory = new CapturingRenderersFactory(applicationContext);
    ExoPlayer player = new ExoPlayer.Builder(applicationContext, capturingRenderersFactory).setClock(new FakeClock(/* isAutoAdvancing= */
    true)).build();
    player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */
    1)));
    PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
    // Ensure the subtitle track is selected.
    DefaultTrackSelector trackSelector = checkNotNull((DefaultTrackSelector) player.getTrackSelector());
    trackSelector.setParameters(trackSelector.buildUponParameters().setPreferredTextLanguage("en"));
    player.setMediaItem(MediaItem.fromUri("asset:///media/dash/webvtt-in-mp4/sample.mpd"));
    player.prepare();
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    DumpFileAsserts.assertOutput(applicationContext, playbackOutput, "playbackdumps/dash/webvtt-in-mp4.dump");
}
Also used : Context(android.content.Context) PlaybackOutput(com.google.android.exoplayer2.robolectric.PlaybackOutput) SurfaceTexture(android.graphics.SurfaceTexture) CapturingRenderersFactory(com.google.android.exoplayer2.testutil.CapturingRenderersFactory) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Surface(android.view.Surface) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)16 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)11 Test (org.junit.Test)10 MediaSource (com.google.android.exoplayer2.source.MediaSource)8 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)7 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)7 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)7 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)7 DefaultRenderersFactory (com.google.android.exoplayer2.DefaultRenderersFactory)6 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)6 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)5 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)5 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)5 TrackSelector (com.google.android.exoplayer2.trackselection.TrackSelector)5 LoadControl (com.google.android.exoplayer2.LoadControl)4 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)4 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)4 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)4 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)4 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)4