Search in sources :

Example 11 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onUpstreamDiscarded.

@Override
public final void onUpstreamDiscarded(int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_UPSTREAM_DISCARDED, listener -> listener.onUpstreamDiscarded(eventTime, mediaLoadData));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 12 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultPlaybackSessionManager method updateCurrentSession.

@RequiresNonNull("listener")
private void updateCurrentSession(EventTime eventTime) {
    if (eventTime.timeline.isEmpty()) {
        // Clear current session if the Timeline is empty.
        currentSessionId = null;
        return;
    }
    @Nullable SessionDescriptor previousSessionDescriptor = sessions.get(currentSessionId);
    SessionDescriptor currentSessionDescriptor = getOrAddSession(eventTime.windowIndex, eventTime.mediaPeriodId);
    currentSessionId = currentSessionDescriptor.sessionId;
    updateSessions(eventTime);
    if (eventTime.mediaPeriodId != null && eventTime.mediaPeriodId.isAd() && (previousSessionDescriptor == null || previousSessionDescriptor.windowSequenceNumber != eventTime.mediaPeriodId.windowSequenceNumber || previousSessionDescriptor.adMediaPeriodId == null || previousSessionDescriptor.adMediaPeriodId.adGroupIndex != eventTime.mediaPeriodId.adGroupIndex || previousSessionDescriptor.adMediaPeriodId.adIndexInAdGroup != eventTime.mediaPeriodId.adIndexInAdGroup)) {
        // New ad playback started. Find corresponding content session and notify ad playback started.
        MediaPeriodId contentMediaPeriodId = new MediaPeriodId(eventTime.mediaPeriodId.periodUid, eventTime.mediaPeriodId.windowSequenceNumber);
        SessionDescriptor contentSession = getOrAddSession(eventTime.windowIndex, contentMediaPeriodId);
        listener.onAdPlaybackStarted(eventTime, contentSession.sessionId, currentSessionDescriptor.sessionId);
    }
}
Also used : MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 13 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onLoadStarted.

// MediaSourceEventListener implementation.
@Override
public final void onLoadStarted(int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
    EventTime eventTime = generateMediaPeriodEventTime(windowIndex, mediaPeriodId);
    sendEvent(eventTime, AnalyticsListener.EVENT_LOAD_STARTED, listener -> listener.onLoadStarted(eventTime, loadEventInfo, mediaLoadData));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 14 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class ExoPlayerImplInternal method getPlaceholderFirstMediaPeriodPositionUs.

private Pair<MediaPeriodId, Long> getPlaceholderFirstMediaPeriodPositionUs(Timeline timeline) {
    if (timeline.isEmpty()) {
        return Pair.create(PlaybackInfo.getDummyPeriodForEmptyTimeline(), 0L);
    }
    int firstWindowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled);
    Pair<Object, Long> firstPeriodAndPositionUs = timeline.getPeriodPositionUs(window, period, firstWindowIndex, /* windowPositionUs= */
    C.TIME_UNSET);
    // Add ad metadata if any and propagate the window sequence number to new period id.
    MediaPeriodId firstPeriodId = queue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(timeline, firstPeriodAndPositionUs.first, /* positionUs= */
    0);
    long positionUs = firstPeriodAndPositionUs.second;
    if (firstPeriodId.isAd()) {
        timeline.getPeriodByUid(firstPeriodId.periodUid, period);
        positionUs = firstPeriodId.adIndexInAdGroup == period.getFirstAdIndexToPlay(firstPeriodId.adGroupIndex) ? period.getAdResumePositionUs() : 0;
    }
    return Pair.create(firstPeriodId, positionUs);
}
Also used : MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)

Example 15 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class ExoPlayerImplInternal method handleMediaSourceListInfoRefreshed.

private void handleMediaSourceListInfoRefreshed(Timeline timeline, boolean isSourceRefresh) throws ExoPlaybackException {
    PositionUpdateForPlaylistChange positionUpdate = resolvePositionForPlaylistChange(timeline, playbackInfo, pendingInitialSeekPosition, queue, repeatMode, shuffleModeEnabled, window, period);
    MediaPeriodId newPeriodId = positionUpdate.periodId;
    long newRequestedContentPositionUs = positionUpdate.requestedContentPositionUs;
    boolean forceBufferingState = positionUpdate.forceBufferingState;
    long newPositionUs = positionUpdate.periodPositionUs;
    boolean periodPositionChanged = !playbackInfo.periodId.equals(newPeriodId) || newPositionUs != playbackInfo.positionUs;
    try {
        if (positionUpdate.endPlayback) {
            if (playbackInfo.playbackState != Player.STATE_IDLE) {
                setState(Player.STATE_ENDED);
            }
            resetInternal(/* resetRenderers= */
            false, /* resetPosition= */
            false, /* releaseMediaSourceList= */
            false, /* resetError= */
            true);
        }
        if (!periodPositionChanged) {
            // We can keep the current playing period. Update the rest of the queued periods.
            if (!queue.updateQueuedPeriods(timeline, rendererPositionUs, getMaxRendererReadPositionUs())) {
                seekToCurrentPosition(/* sendDiscontinuity= */
                false);
            }
        } else if (!timeline.isEmpty()) {
            // Something changed. Seek to new start position.
            @Nullable MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
            while (periodHolder != null) {
                // Update the new playing media period info if it already exists.
                if (periodHolder.info.id.equals(newPeriodId)) {
                    periodHolder.info = queue.getUpdatedMediaPeriodInfo(timeline, periodHolder.info);
                    periodHolder.updateClipping();
                }
                periodHolder = periodHolder.getNext();
            }
            newPositionUs = seekToPeriodPosition(newPeriodId, newPositionUs, forceBufferingState);
        }
    } finally {
        updatePlaybackSpeedSettingsForNewPeriod(/* newTimeline= */
        timeline, newPeriodId, /* oldTimeline= */
        playbackInfo.timeline, /* oldPeriodId= */
        playbackInfo.periodId, /* positionForTargetOffsetOverrideUs */
        positionUpdate.setTargetLiveOffset ? newPositionUs : C.TIME_UNSET);
        if (periodPositionChanged || newRequestedContentPositionUs != playbackInfo.requestedContentPositionUs) {
            Object oldPeriodUid = playbackInfo.periodId.periodUid;
            Timeline oldTimeline = playbackInfo.timeline;
            boolean reportDiscontinuity = periodPositionChanged && isSourceRefresh && !oldTimeline.isEmpty() && !oldTimeline.getPeriodByUid(oldPeriodUid, period).isPlaceholder;
            playbackInfo = handlePositionDiscontinuity(newPeriodId, newPositionUs, newRequestedContentPositionUs, playbackInfo.discontinuityStartPositionUs, reportDiscontinuity, timeline.getIndexOfPeriod(oldPeriodUid) == C.INDEX_UNSET ? Player.DISCONTINUITY_REASON_REMOVE : Player.DISCONTINUITY_REASON_SKIP);
        }
        resetPendingPauseAtEndOfPeriod();
        resolvePendingMessagePositions(/* newTimeline= */
        timeline, /* previousTimeline= */
        playbackInfo.timeline);
        playbackInfo = playbackInfo.copyWithTimeline(timeline);
        if (!timeline.isEmpty()) {
            // Retain pending seek position only while the timeline is still empty.
            pendingInitialSeekPosition = null;
        }
        handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */
        false);
    }
}
Also used : MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)

Aggregations

MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)106 Test (org.junit.Test)85 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)75 Timeline (com.google.android.exoplayer2.Timeline)50 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)48 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)28 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 Nullable (androidx.annotation.Nullable)26 Allocator (com.google.android.exoplayer2.upstream.Allocator)22 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)19 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)17 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)16 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)15 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)15 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)15 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)15 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)11