Instance Method

requestAVAsset(forVideo:options:resultHandler:)

Requests AVFoundation objects representing the video asset’s content and state, to be loaded asynchronously.

Declaration

func requestAVAsset(forVideo asset: PHAsset, options: PHVideoRequestOptions?, resultHandler: @escaping (AVAsset?, AVAudioMix?, [AnyHashable : Any]?) -> Void) -> PHImageRequestID

Parameters

asset

The video asset for which video objects are to be loaded.

options

Options specifying how Photos should handle the request and notify your app of progress or errors. For details, see PHVideoRequestOptions.

resultHandler

A block that Photos calls after loading the asset’s data.

The block takes the following parameters:

asset

An object that provides access to the video asset as a collection of tracks and metadata. For details on working with AVAsset objects, see AVFoundation Programming Guide.

audioMix

Use this object to rearrange the asset’s audio tracks, edit additional audio into the mix, or configure an AVAssetReaderOutput object for exporting the asset’s audio data. If nil, the asset uses a default audio mix.

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 AVFoundation objects. It then calls your resultHandler block to provide the requested video.

Use this method when you want to work with the arrangement of audio and video tracks that an asset contains. If you plan to use the asset only for playback, call the requestPlayerItem(forVideo:options:resultHandler:) method. If you plan to export the asset data, call the requestExportSession(forVideo:options:exportPreset:resultHandler:) method.