Search in sources :

Example 46 with Timeline

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_lateMidrollAdGroupStartTimeUs_adGroupIgnored.

@Test
public void splitAdPlaybackStateForPeriods_lateMidrollAdGroupStartTimeUs_adGroupIgnored() {
    int periodCount = 4;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", // around removed.
    DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs + 2).withAdCount(/* adGroupIndex= */
    0, 1).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    assertThat(adPlaybackStates).hasSize(periodCount);
    for (AdPlaybackState periodAdPlaybackState : adPlaybackStates.values()) {
        assertThat(periodAdPlaybackState.adGroupCount).isEqualTo(0);
    }
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Test(org.junit.Test)

Example 47 with Timeline

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_correctAdPlaybackStates.

@Test
public void splitAdPlaybackStateForPeriods_correctAdPlaybackStates() {
    int periodCount = 7;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", 0).withAdCount(/* adGroupIndex= */
    0, periodCount).withAdDurationsUs(/* adGroupIndex= */
    0, /* adDurationsUs...= */
    DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs, periodDurationUs).withPlayedAd(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0).withSkippedAd(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    1).withAdLoadError(/* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    2).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 0)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_PLAYED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_SKIPPED);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_ERROR);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).getAdGroup(/* adGroupIndex= */
    0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Pair(android.util.Pair) Test(org.junit.Test)

Example 48 with Timeline

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_correctAdsIdInSplitPlaybackStates.

@Test
public void splitAdPlaybackStateForPeriods_correctAdsIdInSplitPlaybackStates() {
    int periodCount = 4;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + 2 * periodDurationUs).withAdCount(/* adGroupIndex= */
    0, 1).withAdDurationsUs(/* adGroupIndex= */
    0, 2 * periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    for (int i = 0; i < adPlaybackStates.size(); i++) {
        assertThat(adPlaybackStates.get(new Pair<>(0L, i)).adsId).isEqualTo("adsId");
    }
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Pair(android.util.Pair) Test(org.junit.Test)

Example 49 with Timeline

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

the class ImaUtilTest method splitAdPlaybackStateForPeriods_midAndPostrollAdGroup_splitCorrectly.

@Test
public void splitAdPlaybackStateForPeriods_midAndPostrollAdGroup_splitCorrectly() {
    int periodCount = 9;
    long periodDurationUs = DEFAULT_WINDOW_DURATION_US / periodCount;
    AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
    "adsId", DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (2 * periodDurationUs), DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (5 * periodDurationUs)).withAdCount(/* adGroupIndex= */
    0, 2).withAdDurationsUs(/* adGroupIndex= */
    0, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    0, true).withAdCount(/* adGroupIndex= */
    1, 2).withAdDurationsUs(/* adGroupIndex= */
    1, periodDurationUs, periodDurationUs).withIsServerSideInserted(/* adGroupIndex= */
    1, true);
    FakeTimeline timeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
    periodCount, /* id= */
    0L));
    ImmutableMap<Object, AdPlaybackState> adPlaybackStates = ImaUtil.splitAdPlaybackStateForPeriods(adPlaybackState, timeline);
    assertThat(adPlaybackStates).hasSize(periodCount);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 0)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 1)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 2)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 3)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 4)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 5)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 6)).adGroupCount).isEqualTo(0);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 7)).adGroupCount).isEqualTo(1);
    assertThat(adPlaybackStates.get(new Pair<>(0L, 8)).adGroupCount).isEqualTo(1);
}
Also used : AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Pair(android.util.Pair) Test(org.junit.Test)

Example 50 with Timeline

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

the class ProgressiveMediaSource method notifySourceInfoRefreshed.

// Internal methods.
private void notifySourceInfoRefreshed() {
    // TODO: Split up isDynamic into multiple fields to indicate which values may change. Then
    // indicate that the duration may change until it's known. See [internal: b/69703223].
    Timeline timeline = new SinglePeriodTimeline(timelineDurationUs, timelineIsSeekable, /* isDynamic= */
    false, /* useLiveConfiguration= */
    timelineIsLive, /* manifest= */
    null, mediaItem);
    if (timelineIsPlaceholder) {
        // TODO: Actually prepare the extractors during preparation so that we don't need a
        // placeholder. See https://github.com/google/ExoPlayer/issues/4727.
        timeline = new ForwardingTimeline(timeline) {

            @Override
            public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
                super.getWindow(windowIndex, window, defaultPositionProjectionUs);
                window.isPlaceholder = true;
                return window;
            }

            @Override
            public Period getPeriod(int periodIndex, Period period, boolean setIds) {
                super.getPeriod(periodIndex, period, setIds);
                period.isPlaceholder = true;
                return period;
            }
        };
    }
    refreshSourceInfo(timeline);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Aggregations

Test (org.junit.Test)347 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)246 Timeline (com.google.android.exoplayer2.Timeline)163 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)140 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)125 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)110 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)109 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)89 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)85 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)79 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)74 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)60 Format (com.google.android.exoplayer2.Format)49 MediaSource (com.google.android.exoplayer2.source.MediaSource)47 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)44 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)38 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)36 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)35 MediaItem (com.google.android.exoplayer2.MediaItem)34 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)33