JWPlayerItemBuilder
@objcMembers
public final class JWPlayerItemBuilder : NSObject, JWBuilder, JWJSONDecodable
The builder for JWPlayerItem, ensuring it is built correctly.
-
Declaration
Swift
public typealias Output = JWPlayerItem -
Undocumented
Declaration
Swift
public override init() -
Returns a
JWPlayerItemBuilderinstance with initial values equal to an existing player item object if provided.These values can still be subsequently assigned. For example, to change the file URL, retaining all the previous player item values:
let breakingNewsVideo = try! JWPlayerItemBuilder(from: currentVideo) .file(breakingNewsVideoURL) .build()Declaration
Swift
public init(from playerItem: JWPlayerItem? = nil)Parameters
playerItemThe
JWPlayerItemobject from which the builder will copy values. -
Returns a
JWPlayerItemBuilderinstance with initial values equal to a valid JSON representation of a player item.These values can still be subsequently assigned. For example, to overwrite the file URL, retaining all the previous player item values:
let breakingNewsVideo = try! JWPlayerItemBuilder(from: currentVideoJsonObject) .file(breakingNewsVideoURL) .build()Declaration
Swift
public convenience init?(from json: JSONObject)Parameters
jsonThe
JSONObjectfrom which the builder will copy values. Must be valid, containing either afileentry, orsourcesarray entry. -
Builds a JWPlayerItem modeled after the specified parameters.
Throws
JWError with key propertyNotSetIf at least one video source is not specified.JWError with key ambiguousVideoSourcesIf both a file and a video source are specified.Declaration
Swift
public func build() throws -> JWPlayerItemReturn Value
A JWPlayerItem object with the provided parameters.
-
Sets a single video source for the player item by providing an URL.
Declaration
Swift
@discardableResult public func file(_ file: URL) -> JWPlayerItemBuilderParameters
fileA String to display as title.
Return Value
The builder, so setters can be chained.
-
Sets the title of the player item.
Note
The string provided is displayed as a literal, and is not looked up in a localized string table.Declaration
Swift
@discardableResult public func title(_ title: String) -> JWPlayerItemBuilderParameters
titleA String to display as title.
Return Value
The builder, so setters can be chained.
-
Sets the description of the player item.
Note
The string provided is displayed as a literal, and is not looked up in a localized string table.Declaration
Swift
@discardableResult public func description(_ description: String) -> JWPlayerItemBuilderParameters
descriptionA String to display as description.
Return Value
The builder, so setters can be chained.
-
Sets the poster image url of the player item.
Declaration
Swift
@discardableResult public func posterImage(_ posterImage: URL) -> JWPlayerItemBuilderParameters
posterImageAn URL that points to the poster image.
Return Value
The builder, so setters can be chained.
-
Sets the number of seconds from the start of a media asset when playback should begin.
Declaration
Swift
@discardableResult public func startTime(_ startTime: TimeInterval) -> JWPlayerItemBuilderParameters
startTimeA TimeInterval value in seconds that determines the start of a media asset when playback should begin.
Return Value
The builder, so setters can be chained.
-
Sets the media identifier of the player item.
Declaration
Swift
@discardableResult public func mediaId(_ mediaId: String) -> JWPlayerItemBuilderParameters
mediaIdA String that represents the player item’s media identifier.
Return Value
The builder, so setters can be chained.
-
Sets the recommendations feed url that contains related items for a particular player item.
Declaration
Swift
@discardableResult public func recommendations(_ recommendations: URL) -> JWPlayerItemBuilderParameters
recommendationsAn URL that represent the player item’s recommendations feed.
Return Value
The builder, so setters can be chained.
-
Sets the video sources which represent the quality levels of the player item.
Declaration
Swift
@discardableResult public func videoSources(_ videoSources: [JWVideoSource]) -> JWPlayerItemBuilderParameters
videoSourcesAn array of
JWVideoSourceobjects representing multiple quality levels of a video.Return Value
The builder, so setters can be chained.
-
Sets the media tracks which provide captions for different languages or thumbnails images of the player item.
Declaration
Swift
@discardableResult public func mediaTracks(_ mediaTracks: [JWMediaTrack]) -> JWPlayerItemBuilderParameters
mediaTracksAn array of
JWMediaTrackobjects providing captions for different languages or thumbnails images.Return Value
The builder, so setters can be chained.
-
Sets the VMAP (Video Multiple Ad Playlist) XML configuration for the player item.
Important
For IMA ads, make sure the player configuration has aJwImaAdvertisingConfigobject (even if it is empty) in addition to providing the ad schedule here. This informs the player of your intention to use the IMA SDK, which cannot be inferred from the ad URL alone.Declaration
Swift
@discardableResult public func adSchedule(vmapXML: String) -> JWPlayerItemBuilderParameters
vmapXMLA raw VMAP XML string defining the ad schedule.
Return Value
The builder, so setters can be chained.
-
Sets a VMAP URL.
Important
For IMA ads, make sure the player configuration has aJwImaAdvertisingConfigobject (even if it is empty) in addition to providing the ad schedule here. This informs the player of your intention to use the IMA SDK, which cannot be inferred from the ad URL alone.Declaration
Swift
@discardableResult public func adSchedule(vmapURL: URL) -> JWPlayerItemBuilderParameters
vmapURLEither a local or remote URL of the vmap file.
Return Value
The builder, so setters can be chained.
-
Sets the advertising schedule which represents a point in the player item time to play the ad.
Important
important For IMA ads, make sure the player configuration has aJwImaAdvertisingConfigobject (even if it is empty) in addition to providing the ad schedule here. This informs the player of your intention to use the IMA SDK, which cannot be inferred from the ad URL alone.Declaration
Swift
@discardableResult public func adSchedule(breaks: [JWAdBreak]?) -> JWPlayerItemBuilderParameters
breaksAn array of
JWAdBreakobjects providing captions for different languages or thumbnail images.Return Value
The builder, so setters can be chained.
-
Sets URL asset.
Note
To see available options, refer to Initialization OptionsDeclaration
Swift
@discardableResult public func assetOptions(_ assetOptions: [String : Any]) -> JWPlayerItemBuilderParameters
assetOptionsA Dictionary of URLAsset initialization options.
Return Value
The builder, so setters can be chained.
-
Sets the Google DAI info which contains either a VoD or Live stream.
Declaration
Swift
@discardableResult public func googleDAIStream(_ googleDAIStream: JWGoogleDAIStream) -> JWPlayerItemBuilderParameters
googleDAIStreamA
JWGoogleDAIStreamobject that provide info about either VoD or Live stream.Return Value
The builder, so setters can be chained.
-
Sets an array of metadata that can be passed externally to supplement the encoded metadata of the underlying media asset.
Note
Supersedes the external metadata specified in theJWPlayerConfiguration, for this player item.Note
Capped at 5 metadata instances; the instances in excess will be excluded.See also
JWExternalMetadataDeclaration
Swift
@discardableResult public func externalMetadata(_ externalMetadata: [JWExternalMetadata]) -> JWPlayerItemBuilderReturn Value
The builder, so setters can be chained.
-
Custom attributes that you can associate with the item.
Use this property to attach a value that provides additional context to the media item. For example, you can attach flags for filtering logic elsewhere in the app, or additional JSON data to be included when serializing the item to be sent over the network, such as credentials for DRM casting to a Chromecast receiver.
Declaration
Swift
@discardableResult public func userInfo(_ userInfo: JSONObject) -> JWPlayerItemBuilderParameters
userInfoThe property stores any additional data that you want to associate with the item.
Return Value
The builder, so setters can be chained.