Package com.google.android.exoplayer2.analytics

## Class DefaultPlaybackSessionManager

- java.lang.Object
- - com.google.android.exoplayer2.analytics.DefaultPlaybackSessionManager

- All Implemented Interfaces:
    `PlaybackSessionManager`

      public final class DefaultPlaybackSessionManager
      extends Object
      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.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.analytics.PlaybackSessionManager

      `PlaybackSessionManager.Listener`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static Supplier<String>` | `DEFAULT_SESSION_ID_GENERATOR` | Default generator for unique session ids that are random, Based64-encoded and URL-safe.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultPlaybackSessionManager()` | Creates session manager with a `DEFAULT_SESSION_ID_GENERATOR` to generate session ids.
    `DefaultPlaybackSessionManager​(Supplier<String> sessionIdGenerator)` | Creates session manager.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `belongsToSession​(AnalyticsListener.EventTime eventTime, String sessionId)` | Returns whether an event time belong to a session.
    `void` | `finishAllSessions​(AnalyticsListener.EventTime eventTime)` | Finishes all existing sessions and calls their respective `PlaybackSessionManager.Listener.onSessionFinished(EventTime, String, boolean)` callback.
    `String` | `getActiveSessionId()` | Returns the session identifier of the session that is currently actively playing, or `null` if there no such session.
    `String` | `getSessionForMediaPeriodId​(Timeline timeline, MediaSource.MediaPeriodId mediaPeriodId)` | Returns the session identifier for the given media period id.
    `void` | `setListener​(PlaybackSessionManager.Listener listener)` | Sets the listener to be notified of session updates.
    `void` | `updateSessions​(AnalyticsListener.EventTime eventTime)` | Updates or creates sessions based on a player `AnalyticsListener.EventTime`.
    `void` | `updateSessionsWithDiscontinuity​(AnalyticsListener.EventTime eventTime, int reason)` | Updates or creates sessions based on a position discontinuity at `AnalyticsListener.EventTime`.
    `void` | `updateSessionsWithTimelineChange​(AnalyticsListener.EventTime eventTime)` | Updates or creates sessions based on a `Timeline` change at `AnalyticsListener.EventTime`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_SESSION_ID_GENERATOR

          public static final Supplier<String> DEFAULT_SESSION_ID_GENERATOR

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

  - ### Constructor Detail

    - #### 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:
        `sessionIdGenerator` - A generator for new session ids. All generated session ids must be unique.

  - ### Method Detail

    - #### setListener

          public void setListener​(PlaybackSessionManager.Listener listener)

      Description copied from interface: `PlaybackSessionManager`
      Sets the listener to be notified of session updates. Must be called before the session manager is used.
      Specified by:
        `setListener` in interface `PlaybackSessionManager`
      Parameters:
        `listener` - The `PlaybackSessionManager.Listener` to be notified of session updates.

    - #### getSessionForMediaPeriodId

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

      Description copied from interface: `PlaybackSessionManager`
      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 `PlaybackSessionManager.Listener` callbacks.

      Specified by:
        `getSessionForMediaPeriodId` in interface `PlaybackSessionManager`
      Parameters:
        `timeline` - The timeline, `mediaPeriodId` is part of.
        `mediaPeriodId` - A `MediaSource.MediaPeriodId`.

    - #### belongsToSession

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

      Description copied from interface: `PlaybackSessionManager`
      Returns whether an event time belong to a session.
      Specified by:
        `belongsToSession` in interface `PlaybackSessionManager`
      Parameters:
        `eventTime` - The `AnalyticsListener.EventTime`.
        `sessionId` - A session identifier.
      Returns:
        Whether the event belongs to the specified session.

    - #### updateSessions

          public void updateSessions​(AnalyticsListener.EventTime eventTime)

      Description copied from interface: `PlaybackSessionManager`
      Updates or creates sessions based on a player `AnalyticsListener.EventTime`.

      Call `PlaybackSessionManager.updateSessionsWithTimelineChange(EventTime)` or `PlaybackSessionManager.updateSessionsWithDiscontinuity(EventTime, int)` if the event is a `Timeline` change or a position discontinuity respectively.

      Specified by:
        `updateSessions` in interface `PlaybackSessionManager`
      Parameters:
        `eventTime` - The `AnalyticsListener.EventTime`.

    - #### updateSessionsWithTimelineChange

          public void updateSessionsWithTimelineChange​(AnalyticsListener.EventTime eventTime)

      Description copied from interface: `PlaybackSessionManager`
      Updates or creates sessions based on a `Timeline` change at `AnalyticsListener.EventTime`.

      Should be called instead of `PlaybackSessionManager.updateSessions(EventTime)` if a `Timeline` change occurred.

      Specified by:
        `updateSessionsWithTimelineChange` in interface `PlaybackSessionManager`
      Parameters:
        `eventTime` - The `AnalyticsListener.EventTime` with the timeline change.

    - #### updateSessionsWithDiscontinuity

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

      Description copied from interface: `PlaybackSessionManager`
      Updates or creates sessions based on a position discontinuity at `AnalyticsListener.EventTime`.

      Should be called instead of `PlaybackSessionManager.updateSessions(EventTime)` if a position discontinuity occurred.

      Specified by:
        `updateSessionsWithDiscontinuity` in interface `PlaybackSessionManager`
      Parameters:
        `eventTime` - The `AnalyticsListener.EventTime` of the position discontinuity.
        `reason` - The `Player.DiscontinuityReason`.

    - #### getActiveSessionId

          @Nullable
          public String getActiveSessionId()

      Description copied from interface: `PlaybackSessionManager`
      Returns the session identifier of the session that is currently actively playing, or `null` if there no such session.
      Specified by:
        `getActiveSessionId` in interface `PlaybackSessionManager`

    - #### finishAllSessions

          public void finishAllSessions​(AnalyticsListener.EventTime eventTime)

      Description copied from interface: `PlaybackSessionManager`
      Finishes all existing sessions and calls their respective `PlaybackSessionManager.Listener.onSessionFinished(EventTime, String, boolean)` callback.
      Specified by:
        `finishAllSessions` in interface `PlaybackSessionManager`
      Parameters:
        `eventTime` - The event time at which sessions are finished.