CachingPlayerItem

public final class CachingPlayerItem : AVPlayerItem

AVPlayerItem subclass that supports caching while playing.

  • Useful for keeping relevant model associated with CachingPlayerItem instance. This is a strong reference, be mindful not to create a retain cycle.

    Declaration

    Swift

    public var passOnObject: Any?
  • Undocumented

    Declaration

    Swift

    public weak var delegate: CachingPlayerItemDelegate?

Public init

  • Play and cache remote media on a local file. saveFilePath is radomly generated. Requires url.pathExtension to not be empty otherwise the player will fail playing.

    Declaration

    Swift

    public convenience init(url: URL, avUrlAssetOptions: [String : Any]? = nil)

    Parameters

    url

    URL referencing the media file.

    avUrlAssetOptions

    A dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.

  • Play and cache remote media on a local file. saveFilePath is radomly generated.

    Declaration

    Swift

    public convenience init(url: URL, customFileExtension: String, avUrlAssetOptions: [String : Any]? = nil)

    Parameters

    url

    URL referencing the media file.

    customFileExtension

    Media file extension. E.g. mp4, mp3. This is required for the player to work correctly with the intended file type.

    avUrlAssetOptions

    A dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.

  • Play and cache remote media.

    Declaration

    Swift

    public init(url: URL, saveFilePath: String, customFileExtension: String?, avUrlAssetOptions: [String : Any]? = nil)

    Parameters

    url

    URL referencing the media file.

    saveFilePath

    The desired local save location. E.g. “video.mp4”. Must be a unique file path that doesn’t already exist. If a file exists at the path than it’s required to be empty (contain no data).

    customFileExtension

    Media file extension. E.g. mp4, mp3. This is required for the player to work correctly with the intended file type.

    avUrlAssetOptions

    A dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.

  • Play remote media without caching.

    Declaration

    Swift

    public init(nonCachingURL url: URL, avUrlAssetOptions: [String : Any]? = nil)

    Parameters

    nonCachingURL

    URL referencing the media file.

    avUrlAssetOptions

    A dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.

  • Play from data.

    Throws

    An error in the Cocoa domain, if there is an error writing to the URL.

    Declaration

    Swift

    public convenience init(data: Data, customFileExtension: String) throws

    Parameters

    data

    Media file represented in data.

    customFileExtension

    Media file extension. E.g. mp4, mp3. This is required for the player to work correctly with the intended file type.

  • Play from file.

    Declaration

    Swift

    public init(filePathURL: URL, fileExtension: String? = nil)

    Parameters

    filePathURL

    The local file path of a media file.

    fileExtension

    Media file extension. E.g. mp4, mp3. Required if filePathURL.pathExtension is empty.

  • Not implemented

    Declaration

    Swift

    override public init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?)

Public methods

  • Downloads the media file. Works only with the initializers intended for play and cache.

    Declaration

    Swift

    public func download()

KVO

  • Undocumented

    Declaration

    Swift

    public override func observeValue(forKeyPath keyPath: String?,
                               of object: Any?,
                               change: [NSKeyValueChangeKey : Any]?,
                               context: UnsafeMutableRawPointer?)