CachingPlayerItem
@MainActor
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
@MainActor public var passOnObject: Any? -
Indicates whether media content is currently being cached to disk. Returns
falsefor initializers that don’t support caching.Declaration
Swift
@MainActor public var isCaching: Bool { get } -
delegatefor status updates.Declaration
Swift
@MainActor public weak var delegate: CachingPlayerItemDelegate?
-
Play and cache remote media on a local file.
saveFilePathis randomly generated. Requiresurl.pathExtensionto not be empty otherwise the player will fail playing.Declaration
Swift
public convenience init(url: URL)Parameters
urlURL referencing the media file.
-
Play and cache remote media on a local file.
saveFilePathis randomly generated. Requiresurl.pathExtensionto not be empty otherwise the player will fail playing.Declaration
Swift
@MainActor public convenience init(url: URL, avUrlAssetOptions: [String : Any]? = nil, configuration: CachingPlayerItemConfiguration = .default)Parameters
urlURL referencing the media file.
avUrlAssetOptionsA dictionary that contains options used to customize the initialization of the asset. For supported keys and values,
configurationConfiguration for the caching and downloading behavior. Defaults to
.default. see Initialization Options. -
Play and cache remote media on a local file.
saveFilePathis randomly generated.Declaration
Swift
@MainActor public convenience init(url: URL, customFileExtension: String, avUrlAssetOptions: [String : Any]? = nil, configuration: CachingPlayerItemConfiguration = .default)Parameters
urlURL referencing the media file.
customFileExtensionMedia file extension. E.g. mp4, mp3. This is required for the player to work correctly with the intended file type.
avUrlAssetOptionsA dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.
configurationConfiguration for the caching and downloading behavior. Defaults to
.default. -
Play and cache remote media.
Declaration
Swift
@MainActor public init(url: URL, saveFilePath: String, customFileExtension: String?, avUrlAssetOptions: [String: Any]? = nil, configuration: CachingPlayerItemConfiguration = .default)Parameters
urlURL referencing the media file.
saveFilePathThe 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).
customFileExtensionMedia file extension. E.g. mp4, mp3. This is required for the player to work correctly with the intended file type.
avUrlAssetOptionsA dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.
configurationConfiguration for the caching and downloading behavior. Defaults to
.default. -
Play remote media without caching.
Declaration
Swift
@MainActor public init(nonCachingURL url: URL, avUrlAssetOptions: [String : Any]? = nil, configuration: CachingPlayerItemConfiguration = .default)Parameters
nonCachingURLURL referencing the media file.
avUrlAssetOptionsA dictionary that contains options used to customize the initialization of the asset. For supported keys and values, see Initialization Options.
configurationConfiguration for the caching and downloading behavior. Defaults to
.default. -
Play from data.
Throws
An error in the Cocoa domain, if there is an error writing to the
URL.Declaration
Swift
@MainActor public convenience init(data: Data, customFileExtension: String, configuration: CachingPlayerItemConfiguration = .default) throwsParameters
dataMedia file represented in data.
customFileExtensionMedia file extension. E.g. mp4, mp3. This is required for the player to work correctly with the intended file type.
configurationConfiguration for the caching and downloading behavior. Defaults to
.default. -
Play from file.
Declaration
Swift
@MainActor public init(filePathURL: URL, fileExtension: String? = nil, configuration: CachingPlayerItemConfiguration = .default)Parameters
filePathURLThe local file path of a media file.
fileExtensionMedia file extension. E.g. mp4, mp3. Required if
filePathURL.pathExtensionis empty.configurationConfiguration for the caching and downloading behavior. Defaults to
.default. -
Play media using an AVAsset. Caching is not supported for this method.
Declaration
Swift
@MainActor override public init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?)Parameters
assetAn instance of AVAsset.
automaticallyLoadedAssetKeysAn NSArray of NSStrings, each representing a property key defined by AVAsset.
-
Downloads the media file. Works only with the initializers intended for play and cache.
Declaration
Swift
@MainActor public func download() -
Cancels the download of the media file and deletes the incomplete cached file. Works only with the initializers intended for play and cache.
Declaration
Swift
@MainActor public func cancelDownload()
-
Undocumented
Declaration
Swift
@MainActor public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
View on GitHub
Install in Dash