Search in sources :

Example 86 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class ExoPlayerTest method setPlaybackSpeed_withAdPlayback_onlyAppliesToContent.

@Test
public void setPlaybackSpeed_withAdPlayback_onlyAppliesToContent() throws Exception {
    // Create renderer with media clock to listen to playback parameter changes.
    ArrayList<PlaybackParameters> playbackParameters = new ArrayList<>();
    FakeMediaClockRenderer audioRenderer = new FakeMediaClockRenderer(C.TRACK_TYPE_AUDIO) {

        private long positionUs;

        @Override
        protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) {
            this.positionUs = offsetUs;
        }

        @Override
        public long getPositionUs() {
            // Continuously increase position to let playback progress.
            positionUs += 10_000;
            return positionUs;
        }

        @Override
        public void setPlaybackParameters(PlaybackParameters parameters) {
            playbackParameters.add(parameters);
        }

        @Override
        public PlaybackParameters getPlaybackParameters() {
            return playbackParameters.isEmpty() ? PlaybackParameters.DEFAULT : Iterables.getLast(playbackParameters);
        }
    };
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(audioRenderer).build();
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs...= */
    0, 7 * C.MICROS_PER_SECOND, C.TIME_END_OF_SOURCE);
    TimelineWindowDefinition adTimelineDefinition = new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* isLive= */
    false, /* isPlaceholder= */
    false, /* durationUs= */
    10 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
    0, /* windowOffsetInFirstPeriodUs= */
    0, adPlaybackState);
    player.setMediaSource(new FakeMediaSource(new FakeTimeline(adTimelineDefinition), ExoPlayerTestRunner.AUDIO_FORMAT));
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.setPlaybackSpeed(5f);
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    player.release();
    // Assert that the renderer received the playback speed updates at each ad/content boundary.
    assertThat(playbackParameters).containsExactly(/* preroll ad */
    new PlaybackParameters(1f), /* content after preroll */
    new PlaybackParameters(5f), /* midroll ad */
    new PlaybackParameters(1f), /* content after midroll */
    new PlaybackParameters(5f), /* postroll ad */
    new PlaybackParameters(1f), /* content after postroll */
    new PlaybackParameters(5f)).inOrder();
    // Assert that user-set speed was reported, but none of the ad overrides.
    verify(mockListener).onPlaybackParametersChanged(any());
    verify(mockListener).onPlaybackParametersChanged(new PlaybackParameters(5.0f));
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ArrayList(java.util.ArrayList) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 87 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class ExoPlayerTest method playSinglePeriodTimeline.

/**
 * Tests playback of a source that exposes a single period.
 */
@Test
public void playSinglePeriodTimeline() throws Exception {
    Timeline timeline = new FakeTimeline();
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT));
    player.prepare();
    player.play();
    runUntilPlaybackState(player, Player.STATE_ENDED);
    InOrder inOrder = Mockito.inOrder(mockListener);
    inOrder.verify(mockListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockListener).onTimelineChanged(argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockListener).onTracksChanged(eq(new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT))), any());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
    inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
    assertThat(renderer.getFormatsRead()).containsExactly(ExoPlayerTestRunner.VIDEO_FORMAT);
    assertThat(renderer.sampleBufferReadCount).isEqualTo(1);
    assertThat(renderer.isEnded).isTrue();
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) Listener(com.google.android.exoplayer2.Player.Listener) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) InOrder(org.mockito.InOrder) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 88 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class DefaultMediaClockTest method rendererNotReady_shouldStillUseRendererClock.

@Test
public void rendererNotReady_shouldStillUseRendererClock() throws ExoPlaybackException {
    MediaClockRenderer mediaClockRenderer = new MediaClockRenderer(/* isReady= */
    false, /* isEnded= */
    false, /* hasReadStreamToEnd= */
    false);
    mediaClock.start();
    mediaClock.onRendererEnabled(mediaClockRenderer);
    // We're not advancing the renderer media clock. Thus, the clock should appear to be stopped.
    assertClockIsStopped();
}
Also used : FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Example 89 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class DefaultMediaClockTest method enableRendererMediaClock_usesRendererClockPosition.

@Test
public void enableRendererMediaClock_usesRendererClockPosition() throws ExoPlaybackException {
    MediaClockRenderer mediaClockRenderer = new MediaClockRenderer();
    mediaClock.start();
    mediaClock.onRendererEnabled(mediaClockRenderer);
    mediaClockRenderer.positionUs = TEST_POSITION_US;
    assertThat(mediaClock.syncAndGetPositionUs(/* isReadingAhead= */
    false)).isEqualTo(TEST_POSITION_US);
    // We're not advancing the renderer media clock. Thus, the clock should appear to be stopped.
    assertClockIsStopped();
}
Also used : FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) Test(org.junit.Test)

Example 90 with Renderer

use of com.google.android.exoplayer2.Renderer in project ExoPlayer by google.

the class TrackSelectionView method init.

/**
 * Initialize the view to select tracks for a specified renderer using {@link MappedTrackInfo} and
 * a set of {@link DefaultTrackSelector.Parameters}.
 *
 * @param mappedTrackInfo The {@link MappedTrackInfo}.
 * @param rendererIndex The index of the renderer.
 * @param isDisabled Whether the renderer should be initially shown as disabled.
 * @param overrides List of initial overrides to be shown for this renderer. There must be at most
 *     one override for each track group. If {@link #setAllowMultipleOverrides(boolean)} hasn't
 *     been set to {@code true}, only the first override is used.
 * @param trackFormatComparator An optional comparator used to determine the display order of the
 *     tracks within each track group.
 * @param listener An optional listener for track selection updates.
 */
public void init(MappedTrackInfo mappedTrackInfo, int rendererIndex, boolean isDisabled, List<SelectionOverride> overrides, @Nullable Comparator<Format> trackFormatComparator, @Nullable TrackSelectionListener listener) {
    this.mappedTrackInfo = mappedTrackInfo;
    this.rendererIndex = rendererIndex;
    this.isDisabled = isDisabled;
    this.trackInfoComparator = trackFormatComparator == null ? null : (o1, o2) -> trackFormatComparator.compare(o1.format, o2.format);
    this.listener = listener;
    int maxOverrides = allowMultipleOverrides ? overrides.size() : Math.min(overrides.size(), 1);
    for (int i = 0; i < maxOverrides; i++) {
        SelectionOverride override = overrides.get(i);
        this.overrides.put(override.groupIndex, override);
    }
    updateViews();
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) AttrRes(androidx.annotation.AttrRes) Arrays(java.util.Arrays) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) AttributeSet(android.util.AttributeSet) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) View(android.view.View) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) C(com.google.android.exoplayer2.C) LayoutInflater(android.view.LayoutInflater) SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull) SparseArray(android.util.SparseArray) List(java.util.List) Nullable(androidx.annotation.Nullable) CheckedTextView(android.widget.CheckedTextView) Comparator(java.util.Comparator) Assertions(com.google.android.exoplayer2.util.Assertions) SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)

Aggregations

Test (org.junit.Test)36 FakeRenderer (com.google.android.exoplayer2.testutil.FakeRenderer)27 Nullable (androidx.annotation.Nullable)25 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)25 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)25 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)24 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)21 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)19 ArrayList (java.util.ArrayList)18 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)17 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)17 MediaSource (com.google.android.exoplayer2.source.MediaSource)16 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)16 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)16 Format (com.google.android.exoplayer2.Format)15 Listener (com.google.android.exoplayer2.Player.Listener)15 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)15 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)14 InOrder (org.mockito.InOrder)14 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)13