JWPlayerProtocol
@objc
public protocol JWPlayerProtocol
Methods and properties for interfacing with the player to control it, and query information.
-
Sets the initial configuration of the player.
Calling this method will reset the player when it is called, even if it has been called before. Any errors during setup or playback will be reported to the JWPlayerDelegate.
Note
This method can be called multiple times throughout the lifecycle of the player, but once invoked it should not be called again untiljwplayerIsReady
or an error has been reported to theJWPlayerDelegate
.Declaration
Swift
func configurePlayer(with configuration: JWPlayerConfiguration)
Parameters
configuration
The config to initialize the player with.
-
The volume relative to the volume of the device. All values are clamped from 0.0 (mute) to 1.0 (current volume of the device).
Declaration
Swift
var volume: Double { get set }
-
The playback rate at which media is being reproduced. The default value is 1.0.
Setting this property to 1.0 will play the media at its natural rate. Ability to set a different value is limited to the rates supported by the media item; if an unsupported rate is requested, playbackRate will not change. Rates between 0.0 and 1.0 will slow forward, rates greater than 1.0 will fast forward, rates between 0.0 and -1.0 will slow reverse, and rates lower than -1.0 will fast reverse. Cannot be set to 0; to pause playback, instead, call the pause method.
Note
This property will have no effect when ads are being played, or when casting.Declaration
Swift
var playbackRate: Double { get set }
-
The position and duration of the currently loaded media.
Declaration
Swift
var time: JWTimeData { get }
-
Informs the player be begin or continue playing the content.
Declaration
Swift
func play()
-
Pauses the currently playing content.
Declaration
Swift
func pause()
-
Stops the player (returning it to the idle state) and unloads the currently playing media file.
Declaration
Swift
func stop()
-
Seeks the player to the given time in seconds.
Declaration
Swift
func seek(to seconds: TimeInterval)
Parameters
seconds
The time to seek to in the video, expressed in seconds.
-
Rewinds the player the given number of seconds.
Declaration
Swift
func rewind(seconds: TimeInterval)
Parameters
seconds
The time to rewind back in the video, expressed in seconds.
-
Fast forwards the player the given number of seconds.
Declaration
Swift
func forward(seconds: TimeInterval)
Parameters
seconds
The time to fast forward in the video, expressed in seconds.
-
Skips the current content, and proceeds to the next item in the playlist.
Declaration
Swift
func next()
-
Stops the current content, and plays the previous video in the playlist.
Declaration
Swift
func previous()
-
Plays an ad immediately, which is primarily useful for situations where the built-in ad schedule of JW Player cannot be used.
In order to utilize this method, you must supply an ad configuration to your
JWPlayerConfiguration
. This configuration can either be empty, or have a default ad tag.let vastConfig = try JWAdsAdvertisingConfigBuilder().build()
or
let imaConfig = try JWImaAdvertisingConfigBuilder().build()
Warning
This function is not avilable for the Google IMA DAI ad client.Declaration
Swift
func play(ad tag: URL, client: JWAdClient)
Parameters
tag
The VAST tag URL that should be loaded into the player.
client
The ad client to use. This feature is not supported by Google IMA DAI.
-
Skips the currently playing ad.
Note
If a skip offset is configured for the currently playing ad, callingskipAd()
will have no effect unless the skip offset is reached.Declaration
Swift
func skipAd()
-
If an ad break is currently playing, discard it and resume content playback. Otherwise, ignore the next scheduled ad break.
Declaration
Swift
func skipAdBreak()
-
Performs a clickthrough on the current advertisement using the default browser.
Note
Does nothing if no ad clickthrough URL is available or no ad is playing.Note
Only available for JWPlayer ads, a warning will be thrown if it is used for other ad clients.Declaration
Swift
func openAdClickthrough()
-
Returns the state of the player.
Declaration
Swift
func getState() -> JWPlayerState
Return Value
A constant denoting the state of the player. If it cannot determine the state,
.unknown
is returned. -
Using the current related content feed, this method plays the content at the given index.
Declaration
Swift
func play(relatedContent index: Int)
Parameters
index
The index of the desired related content.
-
Sets a blocking callback to run before loading the next item in a playlist.
Note
Assigning a callback to this property overwrites any previously assigned callback.Warning
This is a blocking callback, so failure to provide a response to the completion handler will result in unpredictable behavior. Make sure all logical paths do so.Declaration
Swift
func setPlaylistItemCallback(_ callback: @escaping JWPlayerPlaylistItemCallback)
Parameters
callback
A
JWPlayerPlaylistItemCallback
closure used to notify about the next item in a playlist. -
Removes the playlistItem callback (by deregistering the observer).
Declaration
Swift
func removePlaylistItemCallback()
-
Sets the new playlist to the player using its URL.
Declaration
Swift
func loadPlaylist(url: URL)
Parameters
url
A
URL
pointing to a playlist object delivered by the JW Platform Delivery API (signed or unsigned). The requested format should be ‘JSON’ or none — MRSS and XML formats are not supported by the iOS SDK. -
Sets the new playlist to the player.
Declaration
Swift
func loadPlaylist(items: [JWPlayerItem])
Parameters
items
List of content to be played.
-
Loads a player item within the current playlist.
Declaration
Swift
func loadPlayerItemAt(index: Int)
Parameters
index
The index of the desired item within the playlist. If the index is invalid, this method does nothing.
-
A description of the currently playing item.
Declaration
Swift
var currentItem: JWPlayerItem? { get }
-
Returns the cues associated with the currently loaded content.
Note
This should only be called after receiving an onPlaylistItem event. When an onPlaylistItem event fires, the last set of cues are removed.Declaration
Swift
func getCues() -> [JWCue]
Return Value
An array of Cues.
-
Sets the cues associated with the currently loaded content.
Note
This should only be called after receiving an onPlaylistItem event. When an onPlaylistItem event fires, the last set of cues are removed.Declaration
Swift
func setCues(_ cues: [JWCue])
Parameters
cues
An array of Cues.
-
Adds cues to the list of existing cues associated with the currently loaded content.
Note
This should only be called after receiving an onPlaylistItem event. When an onPlaylistItem event fires, the last set of cues are removed.Declaration
Swift
func addCues(_ cues: [JWCue])
Parameters
cues
An array of Cues.
-
Set the captions the index of the currently active captions track. A value of -1 means there is no captions track will be in use.
Throws
If an error is encountered, a JWError is thrown.Declaration
Swift
func setCaptionTrack(index: Int) throws
-
Set the captions track by its locale. If the locale for this track does not exist, this throws a warning. If the locale is set to
nil
then no captions track will be used.Throws
If an error is encountered, a JWError is thrown.Declaration
Swift
func setCaptionTrack(locale: String?) throws
-
Sets player’s caption rendering behavior. If
true
, captions will not be rendered by the player.If a caption track has been chosen, and this flag is set to
true
, caption events will still be reported to theJWAVDelegate
.Note
The default value isfalse
.Declaration
Swift
var suppressesCaptionRendering: Bool { get set }
-
The index of the currently active captions track. A value of -1 means there is no captions track in use.
Declaration
Swift
var currentCaptionsTrack: Int { get set }
-
Returns an array of objects based on available captions. Information for each object may vary depending on the caption types.
The caption tracks are in a predetermined order.
- The first item in the array is alway
None
, for disabling captions. - Embedded captions come second, in an order denoted by the HLS manifest.
- Side-loaded captions are last in the array, in the same order as added to the config.
Declaration
Swift
var captionsTracks: [JWMediaSelectionOption] { get }
- The first item in the array is alway
-
The index of the currently active audio track.
Declaration
Swift
var currentAudioTrack: Int { get set }
-
Returns an array of the playable audio tracks of the current asset in the player.
Declaration
Swift
var audioTracks: [JWMediaSelectionOption] { get }
-
The current visual quality, expressed as an index into the visual quality levels array.
Declaration
Swift
var currentVisualQuality: Int { get set }
-
The index of the playlist item to be played next.
Note
This property only works for regular playlists.Warning
Using this API for recommendations will result in unpredictable behavior.Declaration
Swift
var nextUpPlaylistIndex: Int { get set }
-
Returns an array of the playable visual quality levels of the current asset in the player.
Declaration
Swift
var visualQualityLevels: [JWVideoSource] { get }
-
The current visual quality source.
Declaration
Swift
var visualQuality: JWVisualQuality? { get }
-
A data source delegate which requests the necessary keys to decrypt protected content.
Declaration
Swift
var contentKeyDataSource: JWDRMContentKeyDataSource? { get set }
-
The DRM content loader used for loading locally stored protected content.
This content loader is used to evaluate DRM-protected content. If this is not set, and the
contentDataSource
property is set instead, this property will be populated automatically whenconfigurePlayer(with:)
is called.Declaration
Swift
var contentLoader: JWDRMContentLoader? { get set }
-
An interface to add/remove friendly obstructions
Declaration
Swift
var friendlyObstructions: JWFriendlyObstructionManager { get }