# CastAPI Protocol

    public protocol CastAPI

API for casting (Chromecast, AirPlay).

- `metadata`

  Analytics metadata.

  #### Declaration

  Swift

      var metadata: AnalyticsMetadata? { get set }

- `tracks`

  Generic track list.

  #### Declaration

  Swift

      var tracks: [Track] { get }

- `videoTracks`

  Video track list.

  #### Declaration

  Swift

      var videoTracks: [VideoTrack] { get }

- `audioTracks`

  Audio track list.

  #### Declaration

  Swift

      var audioTracks: [AudioTrack] { get }

- `textTracks`

  Text track list.

  #### Declaration

  Swift

      var textTracks: [TextTrack] { get }

- `isCasting`

  Returns `true` if casting is active.

  #### Declaration

  Swift

      var isCasting: Bool { get }

- `hasConnectedSession`

  Returns `true` if is currently connected to a session.

  #### Declaration

  Swift

      var hasConnectedSession: Bool { get }

- `button`

  Button to activate casting.

  #### Declaration

  Swift

      var button: UIView? { get }

- `miniMediaControlsViewController`

  ViewController with Chromecast mini media controls It is empty for AirPlay.

  #### Declaration

  Swift

      var miniMediaControlsViewController: UIViewController? { get }

- `expandedMediaControlsViewController`

  ViewController with Chromecast expanded media controls It is empty for AirPlay.

  #### Declaration

  Swift

      var expandedMediaControlsViewController: UIViewController? { get }

- `authToken`

  Override authToken passed to

  #### Declaration

  Swift

      var authToken: String? { get set }

- `autoplay`

  Returns `true` If we start playback automatically after content is loaded.

  #### Declaration

  Swift

      var autoplay: Bool? { get set }

- `position`

  Initial playback position.

  #### Declaration

  Swift

      var position: Double? { get set }

- `lastKnownPosition`

  Return the last known remote player playback position. It is read from last ended casting session.

  #### Declaration

  Swift

      var lastKnownPosition: Double? { get }

- `duration`

  Stream duration.

  #### Declaration

  Swift

      var duration: Double { get }

- `subtitlesStyle`

  Custom subtitle style.

  #### Declaration

  Swift

      var subtitlesStyle: SubtitlesStyle? { get set }

- `onMediaUpdate`

  Media status

  #### Declaration

  Swift

      var onMediaUpdate: ((CastMediaStatus) -> Void)? { get set }

- `onCastState`

  Report current cast state.

  #### Declaration

  Swift

      var onCastState: ((CastState) -> Void)? { get set }

- `load(_:)`

  Load configuration.

  #### Declaration

  Swift

      func load(_ playerConfiguration: PlayerConfiguration)

- `presentExpandedMediaControls()`

  Present expanded media controls ViewController

  #### Declaration

  Swift

      func presentExpandedMediaControls()

- `join()`

  Connects and controls existing cast session.

  #### Declaration

  Swift

      func join()

- `play()`

  Start playback.

  #### Declaration

  Swift

      func play()

- `pause()`

  Pause playback.

  #### Declaration

  Swift

      func pause()

- `stop()`

  Stop playback.

  #### Declaration

  Swift

      func stop()

- `endSession(_:)`

  Ends the current cast session.

  #### Declaration

  Swift

      func endSession(_ stopCasting: Bool) -> Bool

  #### Parameters

  `stopCasting` | If `true`, the receiver app stops casting when multiple devices are connected. If `false` and other devices have an active session, the receiver keeps playing. If only one sender device is connected, the receiver app stops casting the media and ignores this parameter.

  #### Return Value

  `true` if the operation to end the session started successfully. `false` if there is no session currently established or if the operation could not be started.

- `seek(_:)`

  Seek to a given time.

  #### Declaration

  Swift

      @available(*, deprecated, message: "Will be removed in 4.1.0, use `seek(_ time: Double﹚` instead.")
      func seek(_ time: CMTime)

  #### Parameters

  `time` | Time to seek.

- `setVideoTrack(_:)`

  CastAPI internally keeps track model adopted for Chromecast

  #### Declaration

  Swift

      func setVideoTrack(_ videoTrack: VideoTrack)