JWPlayerViewController
@objcMembers
open class JWPlayerViewController: UIViewController,
RelatedEventDelegate,
AVPictureInPictureControllerDelegate,
InternalEventHandlerDelegate,
JWPlayerViewDelegate,
JWPlayerDelegate,
JWPlayerStateDelegate,
JWAVDelegate,
JWAdDelegate,
JWAirPlayDelegate,
JWAccessLogMetadataDelegate,
JWDateRangeMetadataDelegate,
JWID3MetadataDelegate,
JWExternalMetadataDelegate,
JWProgramDateTimeMetadataDelegate,
JWMediaMetadataDelegate,
JWCastDelegate,
JWTimeEventListener,
JWChaptersDelegate,
JWRelatedEventDelegate,
UIPopoverPresentationControllerDelegate
This ViewController creates a JWPlayerView
, and creates a default interface for the content.
If you are using JWPlayerViewController
, do not assign another class as a delegate for JWPlayerView
or JWPlayer
and its related delegate properties, nor for JWPlayer.adTimeObserver
and JWPlayer.mediaTimeObserver
. This controller conforms to these delegates already. You can gain access to events by subclassing this, and overriding the methods you are interested in.
Note
If you are writing in Objective-C and want to subclass this ViewController, refer toJWPlayerObjViewController
and subclass that instead.
-
A Boolean value that determines whether the player view allows Picture in Picture playback.
Note
The default value istrue
.Attention
canStartPictureInPictureAutomaticallyFromInline
is not set to true when enabling this property, Picture-in-Picture mode should only be expected to be initiated when using the UI button designated for this.Declaration
Swift
public var allowsPictureInPicturePlayback: Bool { get set }
-
The delegate to receive JWPlayerViewController events.
Declaration
Swift
public weak var delegate: JWPlayerViewControllerDelegate?
-
Returns true if the player is currently in fullscreen mode, and false if it is not
Declaration
Swift
public var isFullScreen: Bool { get }
-
The view containing the player.
Declaration
Swift
public var playerView: JWPlayerViewProtocol { get }
-
The behavior desired for the interface. The default value is
.normal
.Declaration
Swift
public var interfaceBehavior: JWInterfaceBehavior { get set }
-
Available playback rates.
This property is automatically sorted. If an empty array is specified, 1.0 becomes the only available option. Rates must be greater than 0 and less than or equal to 4.0. Invalid rates are removed from the array.
The default rates are: [0.5, 1.0, 1.25, 1.5, 2.0]
Declaration
Swift
public var playbackRates: [Double] { get set }
-
It enables the lock screen controls to be synchronized with the player. The default is
true
.Declaration
Swift
public var enableLockScreenControls: Bool { get set }
-
The number of seconds to wait when fading the interface. The default is 3 seconds.
Note
This only applies wheninterfaceBehavior
is .normal.Declaration
Swift
public var interfaceFadeDelay: TimeInterval
-
The poster image to display when there is no Internet connection. By default, it displays the poster image of the current video.
Declaration
Swift
public var offlinePosterImage: UIImage? { get set }
-
The message that is displayed when the internet connection is lost.
The default value is “This video cannot be played because of a problem with your internet connection.” which corresponds to the localizable string [jwplayer_errors_bad_connection].
Declaration
Swift
public var offlineMessage: String { get set }
-
Returns a Boolean indicating whether to automatically create Chromecast-related UI and update the UI based on Chromecast events.
Override this property in a subclass to signal your intention to not rely on the SDK’s default Chromecast UI integration.
Declaration
Swift
open var handleCastingInternally: Bool { get }
Return Value
true
if yourJWPlayerViewController
subclass lets the SDK handle Chromecast-related UI creation and updates, orfalse
if you intend to display on your own custom UI instead. The default value of this property returnstrue
. -
The JWPlayer interface, used to control playback and configure the player.
Declaration
Swift
public var player: JWPlayerProtocol { get }
-
The default ad interface style to use when presenting JWP VAST ads.
Declaration
Swift
public var adInterfaceStyle: JWAdInterfaceStyle
-
If true, the player will go full screen when rotated into landscape orientation. The default value is
true
.Declaration
Swift
public var forceFullScreenOnLandscape: Bool
-
If true, the player rotates into landscape when it goes into fullscreen. The default value is
true
.Declaration
Swift
public var forceLandscapeOnFullScreen: Bool
-
The style used to customize the player.
Declaration
Swift
public var styling: JWPlayerSkin? { get set }
-
The style defining the Next Up card and its behavior.
Note
If nil is set no Next Up card will be displayed.Declaration
Swift
public var nextUpStyle: JWNextUpStyle? { get set }
-
Sets a custom logo to display on the player.
Declaration
Swift
public var logo: JWLogo? { get set }
-
Called after the controller’s view is loaded into memory. For more information, refer to
UIViewController
documentation.Declaration
Swift
open override func viewDidLoad()
-
Called after the view controller is added or removed from a container view controller. For more information, refer to
UIViewController
documentation.Declaration
Swift
open override func didMove(toParent parent: UIViewController?)
Parameters
parent
The parent view controller, or nil if there is no parent.
-
If your App supports iOS 12 and below, subclasses of JWPlayerViewController require runtime initialization before using it, they won’t be available for Storyboard or Nib use if you have not previously initialized the subclass.
Note
For more information on why this is needed, see the Swift docs.Declaration
Swift
@available(iOS, deprecated: 13.0, message: "No longer needed as SDK 4.17.0+ does not support iOS versions requiring this API.") public static func registerController()
-
Sets the visibility of controls on the player’s interface.
Declaration
Swift
public func setVisibility(_ visibility: JWVisibilityState, for controls: [JWControlType])
Parameters
isVisible
The desired visibility of each control that is provided.
controls
The controls to set the visibility of.
-
Notifies the container that the size of its view is about to change. For more information, refer to
UIViewController
documentation.Declaration
Swift
open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
Parameters
size
The new size for the container’s view.
coordinator
The transition coordinator object managing the size change. You can use this object to animate your changes or get information about the transition that is in progress.
-
This method transitions the player to fullscreen mode. If the player is already in fullscreen mode this method does not perform any actions, and the completion closure will not be executed.
Declaration
Swift
public func transitionToFullScreen(animated: Bool, completion: (() -> Void)? = nil)
Parameters
animated
Set to true if the player should animate into full screen.
completion
This closure is called when the player is done transitioning to full screen mode.
-
This method transitions the player away from fullscreen mode. If the player is not in fullscreen mode this method does not perform any actions, and the completion closure will not be executed.
Declaration
Swift
public func dismissFullScreen(animated: Bool, completion: (() -> Void)? = nil)
Parameters
animated
Set to true if the player should animate away from full screen mode.
completion
This closure is called when the player is done transitioning away from full screen mode.
-
Declaration
Swift
open func playerView(_ view: JWPlayerView, sizeChangedFrom oldSize: CGSize, to newSize: CGSize)
-
Declaration
Swift
open func jwplayerIsReady(_ player: JWPlayer)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, failedWithError code: UInt, message: String)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, failedWithSetupError code: UInt, message: String)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, encounteredWarning code: UInt, message: String)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, encounteredAdError code: UInt, message: String)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, encounteredAdWarning code: UInt, message: String)
-
Declaration
Swift
open func onMediaTimeEvent(_ time: JWTimeData)
-
Declaration
Swift
open func onAdTimeEvent(_ time: JWTimeData)
-
Declaration
Swift
open func jwplayerContentWillComplete(_ player: JWPlayer)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, willPlayWithReason reason: JWPlayReason)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, isBufferingWithReason reason: JWBufferReason)
-
Declaration
Swift
@available(*, deprecated, message: "Instead use jwplayer(_ player: JWPlayer, isBufferingWithReason reason: JWBufferReason﹚") open func jwplayerContentIsBuffering(_ player: JWPlayer)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, updatedBuffer percent: Double, position time: JWTimeData)
-
Declaration
Swift
open func jwplayerContentDidComplete(_ player: JWPlayer)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didFinishLoadingWithTime loadTime: TimeInterval)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, isPlayingWithReason reason: JWPlayReason)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, isAttemptingToPlay playlistItem: JWPlayerItem, reason: JWPlayReason)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didPauseWithReason reason: JWPauseReason)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didBecomeIdleWithReason reason: JWIdleReason)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, usesMediaType type: JWMediaType)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, isVisible: Bool)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didLoadPlaylist playlist: [JWPlayerItem])
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didLoadPlaylistItem item: JWPlayerItem, at index: UInt)
-
Declaration
Swift
open func jwplayerPlaylistHasCompleted(_ player: JWPlayer)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, seekedFrom oldPosition: TimeInterval, to newPosition: TimeInterval)
-
Declaration
Swift
open func jwplayerHasSeeked(_ player: JWPlayer)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, playbackRateChangedTo rate: Double, at time: TimeInterval)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didReceiveAccessLogMetadata metadata: JWAccessLogMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, dateRangeMetadataCueParsed metadata: JWDateRangeMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, dateRangeMetadata metadata: JWDateRangeMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, id3Metadata metadata: JWID3Metadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, externalMetadataCueParsed metadata: JWExternalMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, externalMetadata metadata: JWExternalMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, programDateTimeMetadataCueParsed metadata: JWProgramDateTimeMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, programDateTimeMetadata metadata: JWProgramDateTimeMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, didReceiveMediaMetadata metadata: JWMediaMetadata)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, airPlayStatusChanged status: JWAirPlayStatus)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, audioTracksUpdated levels: [JWMediaSelectionOption])
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, audioTrackChanged currentLevel: Int)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, qualityLevelsUpdated levels: [JWVideoSource])
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, qualityLevelChanged currentLevel: Int)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, visualQualityChanged currentVisualQuality: JWVisualQuality)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, updatedCaptionList options: [JWMediaSelectionOption])
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, captionTrackChanged index: Int)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, captionPresented caption: [String], at time: JWTimeData)
-
Tells the delegate when Picture in Picture is about to start.
Declaration
Swift
open func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController)
Parameters
pictureInPictureController
The Picture in Picture controller to which you’ve assigned the delegate.
-
Tells the delegate that Picture in Picture playback has started.
Declaration
Swift
open func pictureInPictureControllerDidStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController)
Parameters
pictureInPictureController
The Picture in Picture controller to which you’ve assigned the delegate.
-
Tells the delegate when Picture in Picture is about to stop.
Declaration
Swift
open func pictureInPictureControllerWillStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController)
Parameters
pictureInPictureController
The Picture in Picture controller to which you’ve assigned the delegate.
-
Tells the delegate when Picture in Picture playback stops.
Declaration
Swift
open func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController)
Parameters
pictureInPictureController
The Picture in Picture controller to which you’ve assigned the delegate.
-
Tells the delegate when Picture in Picture is about to stop, to give your app an opportunity to restore its video playback user interface.
Note
Make sure to call the completion handler when you have restored the UI, it is important to notify the system of this.Declaration
Swift
open func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void)
Parameters
pictureInPictureController
The Picture in Picture controller to which you’ve assigned the delegate.
completionHandler
To allow the system to finish restoring your user interface, you must call the completion handler with a value of
true
. -
Tells the delegate whether Picture in Picture failed to start.
Declaration
Swift
open func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, failedToStartPictureInPictureWithError error: Error)
Parameters
pictureInPictureController
The Picture in Picture controller to which you’ve assigned the delegate.
error
An error describing why Picture in Picture failed to start.
-
Declaration
Swift
open func castController(_ controller: JWCastController, devicesAvailable devices: [JWCastingDevice])
-
Declaration
Swift
open func castController(_ controller: JWCastController, connectedTo device: JWCastingDevice)
-
Declaration
Swift
open func castController(_ controller: JWCastController, disconnectedWithError error: Error?)
-
Declaration
Swift
open func castController(_ controller: JWCastController, connectionSuspendedWithDevice device: JWCastingDevice)
-
Declaration
Swift
open func castController(_ controller: JWCastController, connectionRecoveredWithDevice device: JWCastingDevice)
-
Declaration
Swift
open func castController(_ controller: JWCastController, connectionFailedWithError error: Error)
-
Declaration
Swift
open func castController(_ controller: JWCastController, castingBeganWithDevice device: JWCastingDevice)
-
Declaration
Swift
open func castController(_ controller: JWCastController, castingFailedWithError error: Error)
-
Declaration
Swift
open func castController(_ controller: JWCastController, castingEndedWithError error: Error?)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, loadedRelatedPlaylist playlist: [JWPlayerItem])
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, loadedNextUpItem item: JWPlayerItem)
-
Declaration
Swift
open func jwplayer(_ player: JWPlayer, relatedItemBeganPlaying item: JWPlayerItem, atIndex index: Int, withMethod method: JWRelatedMethod)
-
Asks the delegate for the presentation style to use when the specified set of traits are active.
Declaration
Swift
public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle
Parameters
controller
The presentation controller that is managing the size change. Use this object to retrieve the view controllers involved in the presentation.
traitCollection
The traits representing the target environment.
-
Notifies the delegate that an adaptivity-related transition is about to occur.
Declaration
Swift
public func presentationController(_ presentationController: UIPresentationController, willPresentWithAdaptiveStyle style: UIModalPresentationStyle, transitionCoordinator: UIViewControllerTransitionCoordinator?)
Parameters
presentationController
The presentation controller that is managing the adaptivity change.
style
The new presentation style. If the presentation style is not changing, this parameter is set to
UIModalPresentationStyle.none
.transitionCoordinator
The transition coordinator that is managing the transition.
-
Sets the visibility of controls on the player’s interface.
Use the
JWControlType
enum to initialize aNSNumber
object with the desired control type.[controller setVisibility:FALSE forControls:@[@(JWControlTypePictureInPictureButton)]]