DefaultPlaybackSessionManager


@UnstableApi
public final class DefaultPlaybackSessionManager implements PlaybackSessionManager


Default PlaybackSessionManager which instantiates a new session for each window in the timeline and also for each ad within the windows.

By default, sessions are identified by Base64-encoded, URL-safe, random strings.

Summary

Constants

static final Supplier<String>

Default generator for unique session ids that are random, Based64-encoded and URL-safe.

Public constructors

Creates session manager with a DEFAULT_SESSION_ID_GENERATOR to generate session ids.

Creates session manager.

Public methods

synchronized boolean
belongsToSession(
    AnalyticsListener.EventTime eventTime,
    String sessionId
)

Returns whether an event time belong to a session.

synchronized void

Finishes all existing sessions and calls their respective onSessionFinished callback.

synchronized @Nullable String

Returns the session identifier of the session that is currently actively playing, or null if there no such session.

synchronized String
getSessionForMediaPeriodId(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the session identifier for the given media period id.

void

Sets the listener to be notified of session updates.

synchronized void

Updates or creates sessions based on a player EventTime.

synchronized void

Updates or creates sessions based on a position discontinuity at EventTime.

synchronized void

Updates or creates sessions based on a Timeline change at EventTime.

Constants

DEFAULT_SESSION_ID_GENERATOR

public static final Supplier<StringDEFAULT_SESSION_ID_GENERATOR

Default generator for unique session ids that are random, Based64-encoded and URL-safe.

Public constructors

DefaultPlaybackSessionManager

public DefaultPlaybackSessionManager()

Creates session manager with a DEFAULT_SESSION_ID_GENERATOR to generate session ids.

DefaultPlaybackSessionManager

public DefaultPlaybackSessionManager(Supplier<String> sessionIdGenerator)

Creates session manager.

Parameters
Supplier<String> sessionIdGenerator

A generator for new session ids. All generated session ids must be unique.

Public methods

belongsToSession

synchronized public boolean belongsToSession(
    AnalyticsListener.EventTime eventTime,
    String sessionId
)

Returns whether an event time belong to a session.

Parameters
AnalyticsListener.EventTime eventTime

The EventTime.

String sessionId

A session identifier.

Returns
boolean

Whether the event belongs to the specified session.

finishAllSessions

synchronized public void finishAllSessions(AnalyticsListener.EventTime eventTime)

Finishes all existing sessions and calls their respective onSessionFinished callback.

Parameters
AnalyticsListener.EventTime eventTime

The event time at which sessions are finished.

getActiveSessionId

synchronized public @Nullable String getActiveSessionId()

Returns the session identifier of the session that is currently actively playing, or null if there no such session.

getSessionForMediaPeriodId

synchronized public String getSessionForMediaPeriodId(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the session identifier for the given media period id.

Note that this will reserve a new session identifier if it doesn't exist yet, but will not call any Listener callbacks.

Parameters
Timeline timeline

The timeline, mediaPeriodId is part of.

MediaSource.MediaPeriodId mediaPeriodId

A MediaPeriodId.

setListener

public void setListener(PlaybackSessionManager.Listener listener)

Sets the listener to be notified of session updates. Must be called before the session manager is used.

Parameters
PlaybackSessionManager.Listener listener

The Listener to be notified of session updates.

updateSessions

synchronized public void updateSessions(AnalyticsListener.EventTime eventTime)

Updates or creates sessions based on a player EventTime.

Call updateSessionsWithTimelineChange or updateSessionsWithDiscontinuity if the event is a Timeline change or a position discontinuity respectively.

Parameters
AnalyticsListener.EventTime eventTime

The EventTime.

updateSessionsWithDiscontinuity

synchronized public void updateSessionsWithDiscontinuity(
    AnalyticsListener.EventTime eventTime,
    @Player.DiscontinuityReason int reason
)

Updates or creates sessions based on a position discontinuity at EventTime.

Should be called instead of updateSessions if a position discontinuity occurred.

Parameters
AnalyticsListener.EventTime eventTime

The EventTime of the position discontinuity.

@Player.DiscontinuityReason int reason

The DiscontinuityReason.

updateSessionsWithTimelineChange

synchronized public void updateSessionsWithTimelineChange(
    AnalyticsListener.EventTime eventTime
)

Updates or creates sessions based on a Timeline change at EventTime.

Should be called instead of updateSessions if a Timeline change occurred.

Parameters
AnalyticsListener.EventTime eventTime

The EventTime with the timeline change.