Package com.castlabs.analytics

# Interface IAnalyticsSession

All Superinterfaces:
  `PlayerControllerPlugin.Component`

All Known Implementing Classes:
  `AnalyticsSession`, `AnalyticsSessionProxy`

public interface IAnalyticsSession extends PlayerControllerPlugin.Component
Base interface for analytics plugins.

Since:
  3.1.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `adClick(String clickthroughUrl)`
  Inform the session that the ad is clicked
  `void`
  `adError(Ad ad, CastlabsPlayerException exception)`
  Inform the session that an ad error occurred.
  `void`
  `adPause()`
  Inform the session that the ad is paused.
  `void`
  `adResume(Ad ad)`
  Inform the session that an ad playback resumed.
  `void`
  `adSkipped()`
  Inform the session that the ad is skipped.
  `void`
  `adStart(Ad ad)`
  Inform the session that an ad playback started.
  `void`
  `adStop()`
  Inform the session that an ad playback stopped.
  `void`
  `adWillStart(Ad ad)`
  Inform the session that an Ad begins loading
  `void`
  `detachFromController()`
  Detach the Analytics session from the PlayerController.
  `void`
  `onExoPlayerStateChanged(boolean playWhenReady, int playbackState)`
  Lets the Analytics Sessions know of any state changes in ExoPlayer.
  `void`
  `release()`
  Terminate the AnalyticsSession.
  `void`
  `reportPlayerState(PlayerController.State state)`
  Report the current player state manually.
  `void`
  `seekEnd()`
  Inform the session that the seeking has completed.
  `void`
  `seekStart(long newPosition)`
  Inform the session that the new position of the video playback is requested.
  `void`
  `sendError(String code, String message, int severity)`
  Send an error manually.
  `void`
  `start(PlayerController playerController, AnalyticsMetaData analyticsMetaData)`
  Start the session on the given controller
  `void`
  `stop()`
  Stop the session.

  ### Methods inherited from interface com.castlabs.android.player.PlayerControllerPlugin.Component

  `id, onDestroy, onOpenBundle, onOpenState`

- ## Method Details

  - ### start

    void start(@NonNull PlayerController playerController, @NonNull AnalyticsMetaData analyticsMetaData)
    Start the session on the given controller
    Parameters:
      `playerController` - The player controller
      `analyticsMetaData` - The meta-data associated with this session

  - ### stop

    void stop()
    Stop the session.

  - ### adWillStart

    void adWillStart(Ad ad)
    Inform the session that an Ad begins loading
    Parameters:
      `ad` - The Ad object. Notice that in this level, some properties of the ad such as `Ad.title` might be null.

  - ### adStart

    void adStart(Ad ad)
    Inform the session that an ad playback started.
    Parameters:
      `ad` - The ad metadata. Contains streamType (Either `SdkConsts.AD_EMBEDDED` if the ad is embedded into the content or `SdkConsts.AD_SEPARATE` if the ad is played separate from the main content.), playerType (Either `SdkConsts.AD_EMBEDDED` if the ad is using the same player as the main content or `SdkConsts.AD_SEPARATE` if the ad is played in a separate player and adPosition The ad position. One of `SdkConsts.AD_POSITION_PREROLL` `SdkConsts.AD_POSITION_MIDROLL` , or `SdkConsts.AD_POSITION_POSTROLL`

  - ### adStop

    void adStop()
    Inform the session that an ad playback stopped.

  - ### adError

    void adError(Ad ad, CastlabsPlayerException exception)
    Inform the session that an ad error occurred.
    Parameters:
      `ad` - The ad
      `exception` - The error's exception

  - ### adSkipped

    void adSkipped()
    Inform the session that the ad is skipped.

  - ### adPause

    void adPause()
    Inform the session that the ad is paused.

  - ### adResume

    void adResume(Ad ad)
    Inform the session that an ad playback resumed. This is usually triggered after an adPause.

    Nevertheless, it is also possible that this event is fired without a preceding adPause. This is the case when re-opening the player from the background with a saved state.

    Parameters:
      `ad` - the ad that has been resumed

  - ### adClick

    void adClick(String clickthroughUrl)
    Inform the session that the ad is clicked
    Parameters:
      `clickthroughUrl` - the clickthrough url of the ad

  - ### reportPlayerState

    void reportPlayerState(PlayerController.State state)
    Report the current player state manually. This is used for the cases that `PlayerListener.onStateChanged(PlayerController.State)` is called before but we want to report it now, same as switching between playlist items in `MultiControllerPlaylist`
    Parameters:
      `state` - The current player state.

  - ### sendError

    void sendError(String code, String message, int severity)
    Send an error manually. Note that the player integration takes care of playback error occurring during playback. Use this method to send error that happen outside of the playback session.
    Parameters:
      `code` - The error code
      `message` - The error message
      `severity` - The severity of the error

  - ### seekStart

    void seekStart(long newPosition)
    Inform the session that the new position of the video playback is requested.
    Parameters:
      `newPosition` - the new position in microseconds

  - ### seekEnd

    void seekEnd()
    Inform the session that the seeking has completed.

    Triggered when the player is ready to continue playback by transitioning to either `PlayerController.State.Playing` or `PlayerController.State.Pausing`.

  - ### detachFromController

    void detachFromController()
    Detach the Analytics session from the PlayerController. Unregister listeners and remove any references.

    This method allows to unbind the AnalyticsSession from a PlayerController, to later set it to a new controller and continue with the same analytics session.

    Should be called by client code after getting the AnalyticsSession via `PlayerController.getAnalyticsSession()` , and before releasing the PlayerController.

    You can later re-attach the AnalyticsSession to a PlayerController before `opening` it with the `PlayerController.setAnalyticsSession(AnalyticsSession)` method

  - ### onExoPlayerStateChanged

    void onExoPlayerStateChanged(boolean playWhenReady, int playbackState)
    Lets the Analytics Sessions know of any state changes in ExoPlayer.

    This method allows any interested Analytics sessions to know of any changes in the ExoPlayer even if it doesn't correspond to any state changes in the PlayerController.

    Parameters:
      `playWhenReady` - Whether playback will proceed when `playbackState` is `Player.STATE_READY`.
      `playbackState` - One of the `STATE` constants.

  - ### release

    void release()
    Terminate the AnalyticsSession. Although implementation is vendor-specific, this method will terminate any ongoing session as if the player itself had been destroyed. Generally, there's no need to call this manually. Unless you're detaching the session and not reusing it later.