# PlayerViewControllerAPI Protocol

    public protocol PlayerViewControllerAPI : UIViewController

Control and manage the player view controller.

- `avPlayerInstance`

  Returns underlining AVPLayer.

  Remark

  Should be used for debugging purpose mainly. Using this object to modify the playback may lead to unexpected and conflicting behaviour with our API.

  #### Declaration

  Swift

      var avPlayerInstance: AVPlayer? { get }

- `playerDelegate`

  The delegate for handling player view controller events.

  #### Declaration

  Swift

      var playerDelegate: PlayerViewControllerProtocol? { get set }

- `playbackState`

  Playback state

  #### Declaration

  Swift

      var playbackState: PlaybackState? { get }

- `isLive`

  Return `true` for live streams, `false` otherwise.

  #### Declaration

  Swift

      var isLive: Bool? { get }

- `seekableTimeRanges`

  A collection of time ranges that the player can seek to. The ranges provided might be discontinuous.

  #### Declaration

  Swift

      var seekableTimeRanges: [CMTimeRange]? { get }

- `allowsPictureInPicturePlayback`

  Determines whether the Picture in Picture feature is enabled.

  #### Declaration

  Swift

      var allowsPictureInPicturePlayback: Bool { get set }

- `closeWhenPlaybackEnd`

  Determines whether the player automatically closes when playback ends.

  #### Declaration

  Swift

      var closeWhenPlaybackEnd: Bool { get set }

- `requiresLinearPlayback`

  Determines whether the content can be skipped by the user.

  #### Declaration

  Swift

      var requiresLinearPlayback: Bool { get set }

- `onState`

  Triggered when playback state has changed.

  #### Declaration

  Swift

      var onState: ((_ previous: PlaybackState, _ state: PlaybackState) -> Void)? { get set }

- `onStats`

  Set callback for playback stats.

  #### Declaration

  Swift

      var onStats: ((Stats) -> Void)? { get set }

- `getStats()`

  Returns playback stats. If stats are not available the returned value is `nil`

  #### Declaration

  Swift

      func getStats() -> Stats?

- `getCurrentChannelIndex()`

  Returns the current channel index of the playlist.

  #### Declaration

  Swift

      func getCurrentChannelIndex() -> Int

- `disableChannelSkipInLiveStream`

  Prevent channel skipping in a live stream.

- `init(channels:analytics:loopChannels:)`

  Initialises an instance of the PlayerViewControllerAPI protocol.

  #### Declaration

  Swift

      init?(
          channels: [ChannelItem],
          analytics: [AnalyticsBackend?: AnalyticsMetadata]?,
          loopChannels: Bool)

  #### Parameters

  `channels` | A list of channels.
  `analytics` | A dictionary containing analytic backend type and metadata for the backend.
  `loopChannels` | Loop the channel list at the first or last channel. Only applicable if the number of channels is greater than 1.

- `replaceCurrentChannel(with:)`

  Replace the current channel item.

  #### Declaration

  Swift

      func replaceCurrentChannel(with channel: ChannelItem) -> Bool

  #### Parameters

  `channel` | The new channel item.

  #### Return Value

  A boolean indicating the success of the replacement.

- `play()`

  Start playback

  #### Declaration

  Swift

      func play()

- `pause()`

  Pause playback

  #### Declaration

  Swift

      func pause()

- `close()`

  Close the player controller

  #### Declaration

  Swift

      func close()

- `setTransportBarActions(_:eventName:)`

  Add custom action controls to the transport bar.

- `setInfoTabActions(_:eventName:)`

  Add custom actions to the info tab.

- `setContextualActions(_:eventName:)`

  Show custom contextual actions.

- `setActionState(ofId:state:title:imageName:)`

  Update the state, title, and image of an action.

- `setChannelMetadata(_:)`

  Update the title, subtitle, description, and artwork image of the player item.

  #### Declaration

  Swift

      func setChannelMetadata(_ metadata: ChannelMetadata)

  #### Parameters

  `metadata` | Additional metadata for the item - title, subtitle, artwork image, and description.

- `seek(_:)`

  Move the playback position.

  #### Declaration

  Swift

      func seek(_ time: CMTime)

- `setRate(_:)`

  Change the playback rate.

  #### Declaration

  Swift

      func setRate(_ rate: Double)

- `getCurrentTime()`

  Return the current playback position.

  #### Declaration

  Swift

      func getCurrentTime() -> CMTime

- `position`

  Returns stream current position.

  #### Declaration

  Swift

      var position: Double? { get }

- `getLiveStartTime()`

  Returns the live start time in seconds since the epoch or `nil` if unknown or not applicable.

  Remark

  Available when player is in state `PlaybackState.ready`.

  #### Declaration

  Swift

      func getLiveStartTime() -> Double?

- `getAudioTrack()`

  Return the currently selected audio track or null if no track is active and selected.

  #### Declaration

  Swift

      func getAudioTrack() -> AudioTrack?

- `getTextTrack()`

  Return the currently selected text track or null if no track is active and selected.

  #### Declaration

  Swift

      func getTextTrack() -> TextTrack?