Search in sources :

Example 1 with MediaSourceEventListener

use of com.google.android.exoplayer2.source.MediaSourceEventListener 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 2 with MediaSourceEventListener

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

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(com.google.android.exoplayer2.Timeline) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) HashSet(java.util.HashSet)

Aggregations

Timeline (com.google.android.exoplayer2.Timeline)1 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)1 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)1 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)1 HashSet (java.util.HashSet)1