Search in sources :

Example 1 with MediaSourceEventListener

use of androidx.media3.exoplayer.source.MediaSourceEventListener in project media by androidx.

the class MediaSourceTestRunner method assertCompletedMediaPeriodLoads.

/**
 * Asserts that the media source reported completed loads via {@link
 * MediaSourceEventListener#onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)} for
 * each specified media period id, and asserts that the associated window index matches the one in
 * the last known timeline returned from {@link #prepareSource()}, {@link #assertTimelineChange()}
 * or {@link #assertTimelineChangeBlocking()}.
 */
public void assertCompletedMediaPeriodLoads(MediaPeriodId... mediaPeriodIds) {
    Timeline.Period period = new Timeline.Period();
    HashSet<MediaPeriodId> expectedLoads = new HashSet<>(Arrays.asList(mediaPeriodIds));
    for (Pair<Integer, MediaPeriodId> windowIndexAndMediaPeriodId : completedLoads) {
        int windowIndex = windowIndexAndMediaPeriodId.first;
        MediaPeriodId mediaPeriodId = windowIndexAndMediaPeriodId.second;
        if (expectedLoads.remove(mediaPeriodId)) {
            int periodIndex = timeline.getIndexOfPeriod(mediaPeriodId.periodUid);
            assertThat(windowIndex).isEqualTo(timeline.getPeriod(periodIndex, period).windowIndex);
        }
    }
    assertWithMessage("Not all expected media source loads have been completed.").that(expectedLoads).isEmpty();
}
Also used : Timeline(androidx.media3.common.Timeline) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) HashSet(java.util.HashSet)

Example 2 with MediaSourceEventListener

use of androidx.media3.exoplayer.source.MediaSourceEventListener in project media by androidx.

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(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)

Aggregations

Timeline (androidx.media3.common.Timeline)1 EventTime (androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)1 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)1 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)1 HashSet (java.util.HashSet)1