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?
-
Undocumented
Declaration
Swift
@MainActor public weak var delegate: CachingPlayerItemDelegate?
-
Play and cache remote media on a local file.
saveFilePath
is randomly generated. Requiresurl.pathExtension
to not be empty otherwise the player will fail playing.Declaration
Swift
public convenience init(url: URL)
Parameters
url
URL referencing the media file.
-
Play and cache remote media on a local file.
saveFilePath
is randomly generated. Requiresurl.pathExtension
to not be empty otherwise the player will fail playing.Declaration
Swift
@MainActor 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 randomly generated.Declaration
Swift
@MainActor 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
@MainActor 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
@MainActor 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
@MainActor 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
@MainActor 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. -
Play media using an AVAsset. Caching is not supported for this method.
Declaration
Swift
@MainActor override public init(asset: AVAsset, automaticallyLoadedAssetKeys: [String]?)
Parameters
asset
An instance of AVAsset.
automaticallyLoadedAssetKeys
An 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?)