Search in sources :

Example 36 with Listener

use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onPlayerStateChanged.

// Implementing and calling deprecated listener method.
@SuppressWarnings("deprecation")
@Override
public final void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, /* eventFlag= */
    C.INDEX_UNSET, listener -> listener.onPlayerStateChanged(eventTime, playWhenReady, playbackState));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 37 with Listener

use of com.google.android.exoplayer2.Player.Listener 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 38 with Listener

use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.

the class DefaultPlaybackSessionManager method updateSessionsWithTimelineChange.

@Override
public synchronized void updateSessionsWithTimelineChange(EventTime eventTime) {
    Assertions.checkNotNull(listener);
    Timeline previousTimeline = currentTimeline;
    currentTimeline = eventTime.timeline;
    Iterator<SessionDescriptor> iterator = sessions.values().iterator();
    while (iterator.hasNext()) {
        SessionDescriptor session = iterator.next();
        if (!session.tryResolvingToNewTimeline(previousTimeline, currentTimeline) || session.isFinishedAtEventTime(eventTime)) {
            iterator.remove();
            if (session.isCreated) {
                if (session.sessionId.equals(currentSessionId)) {
                    currentSessionId = null;
                }
                listener.onSessionFinished(eventTime, session.sessionId, /* automaticTransitionToNextPlayback= */
                false);
            }
        }
    }
    updateCurrentSession(eventTime);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 39 with Listener

use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onMediaItemTransition.

@Override
public final void onMediaItemTransition(@Nullable MediaItem mediaItem, @Player.MediaItemTransitionReason int reason) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_MEDIA_ITEM_TRANSITION, listener -> listener.onMediaItemTransition(eventTime, mediaItem, reason));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 40 with Listener

use of com.google.android.exoplayer2.Player.Listener in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onAvailableCommandsChanged.

@Override
public void onAvailableCommandsChanged(Player.Commands availableCommands) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_AVAILABLE_COMMANDS_CHANGED, listener -> listener.onAvailableCommandsChanged(eventTime, availableCommands));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Aggregations

Test (org.junit.Test)87 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)68 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)58 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)54 Listener (com.google.android.exoplayer2.Player.Listener)45 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)38 MediaSource (com.google.android.exoplayer2.source.MediaSource)38 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)34 ArrayList (java.util.ArrayList)33 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)31 Nullable (androidx.annotation.Nullable)27 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)27 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)26 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)26 PositionInfo (com.google.android.exoplayer2.Player.PositionInfo)25 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)25 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 InOrder (org.mockito.InOrder)22 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)21