Package com.castlabs.sdk.googlecast

## Class GoogleCastManager

- java.lang.Object
- - com.castlabs.sdk.googlecast.GoogleCastManager

-     public final class GoogleCastManager
      extends Object

  Utility class that allows to start and control a Google Cast session
  Since:
    4.0.1

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `GoogleCastManager.CastInfoProvider` | Optional cast info provider to add or modify request cast params.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static String` | `INTENT_STREAM_DURATION` | Stream duration.
    `static String` | `INTENT_STREAM_LIVE` | Stream type.
    `static String` | `INTENT_SUBTITLES_STYLE` | Subtitles style.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static RemotePlayerState` | `getCurrentPlayerState​(com.google.android.gms.cast.framework.SessionManager sessionManager)` | Provides the current remote player state.
    `static SubtitlesStyle` | `getSubtitleStyle​(com.google.android.gms.cast.framework.SessionManager sessionManager)` | Returns the currently set Subtitle style on the RemoteMediaClient
    `static void` | `selectAudioTrack​(com.google.android.gms.cast.framework.SessionManager sessionManager, RemotePlayerState playerState, AudioTrack audioTrack)` | Select a remote audio track
    `static void` | `selectSubtitleTrack​(com.google.android.gms.cast.framework.SessionManager sessionManager, RemotePlayerState playerState, SubtitleTrack subtitleTrack)` | Select a remote subtitle track
    `static void` | `selectVideoQuality​(com.google.android.gms.cast.framework.SessionManager sessionManager, RemotePlayerState playerState, VideoTrackQuality videoTrackQuality)` | Select a remote video quality track
    `static void` | `setCastInfoProvider​(GoogleCastManager.CastInfoProvider provider)` | Sets a `GoogleCastManager.CastInfoProvider` that will be called before sending the config to the remote cast device.
    `static void` | `setSubtitleStyle​(com.google.android.gms.cast.framework.SessionManager sessionManager, SubtitlesStyle subtitlesStyle)` | Sets the subtitle style of the remote player.
    `static void` | `setSubtitleStyle​(com.google.android.gms.cast.framework.SessionManager sessionManager, SubtitlesStyle subtitlesStyle, String fontFamily)` | Sets the subtitle style of the remote player.
    `static void` | `startCasting​(Bundle intentBundle, com.google.android.gms.cast.framework.SessionManager sessionManager, com.google.android.gms.cast.MediaMetadata metadata)` | Start casting with the configuration provided in a Bundle.
    `static void` | `startCasting​(PlayerController playerController, com.google.android.gms.cast.framework.SessionManager sessionManager, com.google.android.gms.cast.MediaMetadata metadata)` | Start casting whatever the provided PlayerController is playing.

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

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

- - ### Field Detail

    - #### INTENT_STREAM_DURATION

          public static final String INTENT_STREAM_DURATION

      Stream duration. If not informed, `MediaInfo.UNKNOWN_DURATION` will be sent to the receiver. A `long` is expected.
      See Also:
        Constant Field Values

    - #### INTENT_STREAM_LIVE

          public static final String INTENT_STREAM_LIVE

      Stream type. Will send `MediaInfo.STREAM_TYPE_LIVE` if `true`, `MediaInfo.STREAM_TYPE_BUFFERED` if `false` or `MediaInfo.STREAM_TYPE_INVALID` if not informed. A `boolean` is expected.
      See Also:
        Constant Field Values

    - #### INTENT_SUBTITLES_STYLE

          public static final String INTENT_SUBTITLES_STYLE

      Subtitles style. An instance of `SubtitlesStyle` is expected.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### setCastInfoProvider

          public static void setCastInfoProvider​(@Nullable
                                                 GoogleCastManager.CastInfoProvider provider)

      Sets a `GoogleCastManager.CastInfoProvider` that will be called before sending the config to the remote cast device. This gives the chance to query and modify any info that is being sent.
      Parameters:
        `provider` - an instance of `GoogleCastManager.CastInfoProvider`

    - #### startCasting

          public static void startCasting​(@NonNull
                                          PlayerController playerController,
                                          @NonNull
                                          com.google.android.gms.cast.framework.SessionManager sessionManager,
                                          @Nullable
                                          com.google.android.gms.cast.MediaMetadata metadata)

      Start casting whatever the provided PlayerController is playing. Playback position, language and subtitles will be transmitted to the cast API. Cast sessions will always start on Adaptive bitrate, regardless of the PlayerController setting.
      Parameters:
        `playerController` - Where to get the needed info to start casting
        `sessionManager` - Cast session manager
        `metadata` - additional metadata to set to the `MediaInfo` object.

    - #### startCasting

          public static void startCasting​(@Nullable
                                          Bundle intentBundle,
                                          @NonNull
                                          com.google.android.gms.cast.framework.SessionManager sessionManager,
                                          @Nullable
                                          com.google.android.gms.cast.MediaMetadata metadata)

      Start casting with the configuration provided in a Bundle. This method expects the same Bundle structure as in `PlayerController.open(Bundle)`.
      Parameters:
        `intentBundle` - Where to get the needed info to start casting
        `sessionManager` - Cast session manager
        `metadata` - additional metadata to set to the `MediaInfo` object.

    - #### getCurrentPlayerState

          public static RemotePlayerState getCurrentPlayerState​(com.google.android.gms.cast.framework.SessionManager sessionManager)

      Provides the current remote player state. This includes the available tracks and the currently selected video quality, audio, and subtitle tracks.

      The object returned by this method is required by the `select` methods.
      Parameters:
        `sessionManager` - cast session manager
      Returns:
        a RemotePlayerState instance representing the remote player state

    - #### selectVideoQuality

          public static void selectVideoQuality​(@NonNull
                                                com.google.android.gms.cast.framework.SessionManager sessionManager,
                                                @NonNull
                                                RemotePlayerState playerState,
                                                @Nullable
                                                VideoTrackQuality videoTrackQuality)

      Select a remote video quality track
      Parameters:
        `sessionManager` - cast session manager
        `playerState` - current player state as returned by `getCurrentPlayerState(SessionManager)`
        `videoTrackQuality` - desired new video quality track. If null ABR will be used

    - #### selectAudioTrack

          public static void selectAudioTrack​(@NonNull
                                              com.google.android.gms.cast.framework.SessionManager sessionManager,
                                              @NonNull
                                              RemotePlayerState playerState,
                                              @NonNull
                                              AudioTrack audioTrack)

      Select a remote audio track
      Parameters:
        `sessionManager` - cast session manager
        `playerState` - current player state as returned by `getCurrentPlayerState(SessionManager)`
        `audioTrack` - desired new audio track

    - #### selectSubtitleTrack

          public static void selectSubtitleTrack​(@NonNull
                                                 com.google.android.gms.cast.framework.SessionManager sessionManager,
                                                 @NonNull
                                                 RemotePlayerState playerState,
                                                 @Nullable
                                                 SubtitleTrack subtitleTrack)

      Select a remote subtitle track
      Parameters:
        `sessionManager` - cast session manager
        `playerState` - current player state as returned by `getCurrentPlayerState(SessionManager)`
        `subtitleTrack` - desired new subtitle track. If null subtitles will be disabled

    - #### setSubtitleStyle

          public static void setSubtitleStyle​(@NonNull
                                              com.google.android.gms.cast.framework.SessionManager sessionManager,
                                              @NonNull
                                              SubtitlesStyle subtitlesStyle)

      Sets the subtitle style of the remote player.

      If you want to set the font family, you should use `setSubtitleStyle(SessionManager, SubtitlesStyle, String)` as there's no reliable way to get the font family name from a `Typeface` object.

      Parameters:
        `sessionManager` - cast session manager
        `subtitlesStyle` - desired new subtitle style

    - #### setSubtitleStyle

          public static void setSubtitleStyle​(@NonNull
                                              com.google.android.gms.cast.framework.SessionManager sessionManager,
                                              @NonNull
                                              SubtitlesStyle subtitlesStyle,
                                              @Nullable
                                              String fontFamily)

      Sets the subtitle style of the remote player.
      Parameters:
        `sessionManager` - cast session manager
        `subtitlesStyle` - desired new subtitle style
        `fontFamily` - desired font family. If null default family will be used

    - #### getSubtitleStyle

          @Nullable
          public static SubtitlesStyle getSubtitleStyle​(@NonNull
                                                        com.google.android.gms.cast.framework.SessionManager sessionManager)

      Returns the currently set Subtitle style on the RemoteMediaClient
      Parameters:
        `sessionManager` - cast session manager
      Returns:
        the SubtitlesStyle, or null if it's un-accessible