Set up a player (iOS)

Implement the JWP player in your iOS app


To set up a player, use JWPlayerViewController. This view controller can be presented in the following ways:

  • Presented directly (full screen)
  • Embedded in a container view (partial screen)

The view controller uses 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.

πŸ”‘

For flexibility and control over how the player is presented and integrated into your app's user interface, you can set up a player with the JWPlayerView.



Implementation

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



Using Player APIs

Content Handling APIs

To use the player content handling APIs, the playerIsReady event must have already been initiated. The playerIsReady event is called once the player property of the JWPlayerViewController 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 the view controller, do not override the delegates in 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.

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 below.

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 }