Commit 394ab7bc by tonihei Committed by Oliver Woodman

Make use of position discontinuity changes.

The extended onPositionDiscontinuity callback can be used to improve some
listener classes:
 - Listening to onTimelineChanged to detect discontinuities is no longer needed.
 - Listening to onSeekStarted is no longer needed as the start position is part
   of the onPositionDiscontinuty callback.
 - The exact old position is also useful for media time history logging.

As a side effect, removing onSeekStarted handling from PlaybackStatsListener
fixes Issue: #8675 that was caused by the special EventTime handling for
onSeekStarted.

PiperOrigin-RevId: 365558959
parent 47af9a68
...@@ -33,6 +33,7 @@ import java.util.HashMap; ...@@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/** /**
* Default {@link PlaybackSessionManager} which instantiates a new session for each window in the * Default {@link PlaybackSessionManager} which instantiates a new session for each window in the
...@@ -184,7 +185,7 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag ...@@ -184,7 +185,7 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag
} }
} }
} }
updateSessionsWithDiscontinuity(eventTime, Player.DISCONTINUITY_REASON_INTERNAL); updateCurrentSession(eventTime);
} }
@Override @Override
...@@ -208,6 +209,31 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag ...@@ -208,6 +209,31 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag
} }
} }
} }
updateCurrentSession(eventTime);
}
@Override
@Nullable
public synchronized String getActiveSessionId() {
return currentSessionId;
}
@Override
public synchronized void finishAllSessions(EventTime eventTime) {
currentSessionId = null;
Iterator<SessionDescriptor> iterator = sessions.values().iterator();
while (iterator.hasNext()) {
SessionDescriptor session = iterator.next();
iterator.remove();
if (session.isCreated && listener != null) {
listener.onSessionFinished(
eventTime, session.sessionId, /* automaticTransitionToNextPlayback= */ false);
}
}
}
@RequiresNonNull("listener")
private void updateCurrentSession(EventTime eventTime) {
@Nullable SessionDescriptor previousSessionDescriptor = sessions.get(currentSessionId); @Nullable SessionDescriptor previousSessionDescriptor = sessions.get(currentSessionId);
SessionDescriptor currentSessionDescriptor = SessionDescriptor currentSessionDescriptor =
getOrAddSession(eventTime.windowIndex, eventTime.mediaPeriodId); getOrAddSession(eventTime.windowIndex, eventTime.mediaPeriodId);
...@@ -234,20 +260,6 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag ...@@ -234,20 +260,6 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag
} }
} }
@Override
public void finishAllSessions(EventTime eventTime) {
currentSessionId = null;
Iterator<SessionDescriptor> iterator = sessions.values().iterator();
while (iterator.hasNext()) {
SessionDescriptor session = iterator.next();
iterator.remove();
if (session.isCreated && listener != null) {
listener.onSessionFinished(
eventTime, session.sessionId, /* automaticTransitionToNextPlayback= */ false);
}
}
}
private SessionDescriptor getOrAddSession( private SessionDescriptor getOrAddSession(
int windowIndex, @Nullable MediaPeriodId mediaPeriodId) { int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
// There should only be one matching session if mediaPeriodId is non-null. If mediaPeriodId is // There should only be one matching session if mediaPeriodId is non-null. If mediaPeriodId is
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.analytics; package com.google.android.exoplayer2.analytics;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Player.DiscontinuityReason; import com.google.android.exoplayer2.Player.DiscontinuityReason;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime; import com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime;
...@@ -129,6 +130,13 @@ public interface PlaybackSessionManager { ...@@ -129,6 +130,13 @@ public interface PlaybackSessionManager {
void updateSessionsWithDiscontinuity(EventTime eventTime, @DiscontinuityReason int reason); void updateSessionsWithDiscontinuity(EventTime eventTime, @DiscontinuityReason int reason);
/** /**
* Returns the session identifier of the session that is currently actively playing, or {@code
* null} if there no such session.
*/
@Nullable
String getActiveSessionId();
/**
* Finishes all existing sessions and calls their respective {@link * Finishes all existing sessions and calls their respective {@link
* Listener#onSessionFinished(EventTime, String, boolean)} callback. * Listener#onSessionFinished(EventTime, String, boolean)} callback.
* *
......
...@@ -188,11 +188,6 @@ public class EventLogger implements AnalyticsListener { ...@@ -188,11 +188,6 @@ public class EventLogger implements AnalyticsListener {
} }
@Override @Override
public void onSeekStarted(EventTime eventTime) {
logd(eventTime, "seekStarted");
}
@Override
public void onPlaybackParametersChanged( public void onPlaybackParametersChanged(
EventTime eventTime, PlaybackParameters playbackParameters) { EventTime eventTime, PlaybackParameters playbackParameters) {
logd(eventTime, "playbackParameters", playbackParameters.toString()); logd(eventTime, "playbackParameters", playbackParameters.toString());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment