Set up a player (iOS v4 | tvOS)

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 }