requestPlayerItem(forVideo:options:resultHandler:)
Requests a representation of the video asset for playback, to be loaded asynchronously.
Declaration
func requestPlayerItem(forVideo asset: PHAsset, options: PHVideoRequestOptions?, resultHandler: @escaping (AVPlayerItem?, [AnyHashable : Any]?) -> Void) -> PHImageRequestIDParameters
- asset:
The video asset to be played back.
- options:
Options specifying how Photos should handle the request and notify your app of progress or errors. For details, see Phvideorequestoptions.
- resultHandler:
A block Photos calls after loading the asset’s data and preparing the player item.
The block takes the following parameters:
- playerItem
An Avplayeritem object that you can use for playing back the video asset.
- info
A dictionary providing information about the status of the request. See Image Result Info Keys for possible keys and values.
Return Value
A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest(_:) method.
Discussion
When you call this method, Photos downloads the video data (if necessary) and creates a player item. It then calls your resultHandler block to provide the requested video.
Use this method when you want to simply play back the video asset as it currently exists. For more detailed options or to work with the asset’s audio and video tracks, use the requestAVAsset(forVideo:options:resultHandler:) method instead.