Set up a player with JWPlayerView (iOS)

Implement the JWP player in your iOS app


Setting up a player with JWPlayerView gives you flexibility and control over how the player is presented and integrated into your app's user interface. JWPlayerView is a UIView subclass that provides the core functionality of the JWP player without a pre-built user interface.

This approach offers several advantages:

  • Embed JWPlayerView into an existing view hierarchy
  • Control the size and position of the player
  • Create custom controls
  • Create and manage multiple player instances on a single screen
  • Use JWPlayerView with complex layouts, such as table views, collection views, and alongside other UI components

πŸ”‘

You can set up a player with the JWPlayerViewController if you prefer a pre-built user interface.



Implementation

Use the Custom UI - Best Practice App to set up a player with the JWPlayerView.



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 setup has finished successfully. Then, the event is sent to the JWPlayerDelegate.

You can listen for player events to occur. Once the event occurs, you can define an appropriate response.

🚧

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


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 }