Set up a player (iOS)

Implement the JWPlayer to your tvOS app.





To set up a player, use either JWPlayerViewController(iOS) or JWCinematicViewController(tvOS). Like any UIViewController, either view controller can be presented in the following ways:

  • Presented directly (full screen)
  • Embedded in a container view (partial screen)1
    1. The JWCinematicViewController is intended to only be presented directly in full screen.

Both view controllers use the default JWP user interface. If you subclass the view controller, you can listen for all of the events related to the player and the user interface.



Implementation

Use the following steps to set up a player with the JWPlayerViewController or JWCinematicViewController:



Using Player APIs

Content Handling APIs

To use the player content handling APIs, the playerIsReady (iOS | tvOS) event must have already been initiated. The playerIsReady event is called once the player property of the JWPlayerViewController or JWCinematicViewController object has finished setup. Then, the event is sent to the JWPlayerDelegate.

Unless set to another object, the JWPlayerDelegate is set to the JWPlayerViewController.

🚧

When subclassing either view controller, do not override the delegates in JWPlayerView or JWPlayer.


Values related to the currently loaded item such as player.currentItem will be set once the didLoadPlaylistItem delegate method is called.

   // MARK: - JWPlayerDelegate
 
   // Player is ready
   override func jwplayerIsReady(_ player: JWPlayer) {
   }
 
   // Setup error, player is not ready
   override func jwplayer(_ player: JWPlayer, failedWithSetupError code: UInt, message: String) {
   }

The content handling APIs are listed below:

FunctionsVariables
β€’ func forward(seconds: TimeInterval)

β€’ func getState() -> JWPlayerState

β€’ func loadPlayerItemAt(index: Int)

β€’ func loadPlaylist(_ playlist: [JWPlayerItem])

β€’ func next()

β€’ func pause()

β€’ func play()

β€’ func play(ad tag: URL, client: JWAdClient)

β€’ func previous()

β€’ func rewind(seconds: TimeInterval)

β€’ func seek(to seconds: TimeInterval)

β€’ func skipAd()

β€’ func stop()
β€’ var currentItem: JWPlayerItem? {get}

β€’ var playbackRate: Double { get set }

β€’ var time: JWTimeData { get }

β€’ var volume: Double { get set }

Non-content Handling APIs

APIs that do not relate to content handling can be accessed and used prior to the playerIsReady event being initiated.

The non-content handling APIs are listed in the following table.

FunctionEvent Delegates
β€’ func configurePlayer(with configuration: JWPlayerConfiguration)β€’ delegate: JWPlayerDelegate? { get set }

β€’ var contentKeyDataSource: JWDRMContentKeyDataSource? { get set }

β€’ var playbackStateDelegate: JWPlayerStateDelegate? { get set }

β€’ var adDelegate: JWAdDelegate? { get set }

β€’ var adTimeObserver: ((JWTimeData) -> Void)? { get set }

β€’ var airPlayDelegate: JWAirPlayDelegate? { get set }

β€’ var avDelegate: JWAVDelegate? { get set }

β€’ var friendlyObstructions: JWFriendlyObstructionManager { get }

β€’ var mediaTimeObserver: ((JWTimeData) -> Void)? { get set }

β€’ var metadataDelegates: JWMetadataDelegates { get }