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 JWPlayerItemBuilder instance 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

    playerItem

    The JWPlayerItem object from which the builder will copy values.

  • Returns a JWPlayerItemBuilder instance 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

    json

    The JSONObject from which the builder will copy values. Must be valid, containing either a file entry, or sources array entry.

  • Builds a JWPlayerItem modeled after the specified parameters.

    Throws

    JWError with key propertyNotSet If at least one video source is not specified. JWError with key ambiguousVideoSources If both a file and a video source are specified.

    Declaration

    Swift

    public func build() throws -> JWPlayerItem

    Return 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) -> JWPlayerItemBuilder

    Parameters

    file

    A 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) -> JWPlayerItemBuilder

    Parameters

    title

    A 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) -> JWPlayerItemBuilder

    Parameters

    description

    A 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) -> JWPlayerItemBuilder

    Parameters

    posterImage

    An 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) -> JWPlayerItemBuilder

    Parameters

    startTime

    A 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) -> JWPlayerItemBuilder

    Parameters

    mediaId

    A 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) -> JWPlayerItemBuilder

    Parameters

    recommendations

    An 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]) -> JWPlayerItemBuilder

    Parameters

    videoSources

    An array of JWVideoSource objects 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]) -> JWPlayerItemBuilder

    Parameters

    mediaTracks

    An array of JWMediaTrack objects providing captions for different languages or thumbnails images.

    Return Value

    The builder, so setters can be chained.

  • Sets a VMAP URL.

    Important

    For IMA ads, make sure the player configuration has a JwImaAdvertisingConfig object (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) -> JWPlayerItemBuilder

    Parameters

    vmapURL

    Either 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 a JwImaAdvertisingConfig object (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]?) -> JWPlayerItemBuilder

    Parameters

    breaks

    An array of JWAdBreak objects 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 Options

    Declaration

    Swift

    @discardableResult
    public func assetOptions(_ assetOptions: [String : Any]) -> JWPlayerItemBuilder

    Parameters

    assetOptions

    A 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) -> JWPlayerItemBuilder

    Parameters

    googleDAIStream

    A JWGoogleDAIStream object 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 the JWPlayerConfiguration, for this player item.

    Note

    Capped at 5 metadata instances; the instances in excess will be excluded.

    Declaration

    Swift

    @discardableResult
    public func externalMetadata(_ externalMetadata: [JWExternalMetadata]) -> JWPlayerItemBuilder

    Return 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) -> JWPlayerItemBuilder

    Parameters

    userInfo

    The property stores any additional data that you want to associate with the item.

    Return Value

    The builder, so setters can be chained.