# 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 currently connected to a cast 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.2.0, use `seek(_ time: Double﹚` instead.")
      func seek(_ time: CMTime)

  #### Parameters

  `time` | Time to seek.

- `seek(_:)`

  Seeks remote playback to an absolute position in seconds.

  #### Declaration

  Swift

      func seek(_ time: Double)

  #### Parameters

  `time` | Target position in seconds.

- `setVideoTrack(_:)`

  Updates the selected remote video track in the cast receiver.

  #### Declaration

  Swift

      func setVideoTrack(_ videoTrack: VideoTrack)

- `setAudioTrack(_:)`

  Updates the selected remote audio track in the cast receiver.

  #### Declaration

  Swift

      func setAudioTrack(_ audioTrack: AudioTrack)

- `setTextTrack(_:)`

  Updates the selected remote text track in the cast receiver.

  #### Declaration

  Swift

      func setTextTrack(_ textTrack: TextTrack)

- `getVideoTrack()`

  Returns the currently selected remote video track.

  #### Declaration

  Swift

      func getVideoTrack() -> VideoTrack?

- `getAudioTrack()`

  Returns the currently selected remote audio track.

  #### Declaration

  Swift

      func getAudioTrack() -> AudioTrack?

- `getTextTrack()`

  Returns the currently selected remote text track.

  #### Declaration

  Swift

      func getTextTrack() -> TextTrack?