A reader object used to obtain the media data of an asset, either file-based or consisting of an assemblage of media data from multiple sources.


class AVAssetReader : NSObject


AVAssetReader lets you:

The AVAssetReader pipelines are multithreaded internally. After you initiate reading with init(asset:), a reader loads and processes a reasonable amount of sample data ahead of use so that retrieval operations such as copyNextSampleBuffer() (AVAssetReaderOutput) can have very low latency. AVAssetReader is not intended for use with real-time sources, and its performance is not guaranteed for real-time operations.


Creating a Reader

init(asset: AVAsset)

Creates an asset reader for reading media data from a specified asset.

Managing Outputs

var outputs: [AVAssetReaderOutput]

The outputs from which clients of the reader can read media data.

func add(AVAssetReaderOutput)

Adds an output to the receiver.

func canAdd(AVAssetReaderOutput) -> Bool

Returns a Boolean value that indicates whether to add an output to the receiver.

Controlling Reading

var status: AVAssetReader.Status

The status of the reading of sample buffers from the asset.

enum AVAssetReader.Status

The statuses for a reader.

func startReading() -> Bool

Prepares the receiver for obtaining sample buffers from the asset.

func cancelReading()

Cancels any background work and prevents the receiver’s outputs from reading more samples.

var error: Error?

Describes the error that occurred.

var timeRange: CMTimeRange

The time range to read from the asset.

Getting the Asset

var asset: AVAsset

The asset that initialized the receiver.


Inherits From

Conforms To

See Also

File Import

class AVAssetReaderAudioMixOutput

An object that defines an interface for reading audio samples that result from mixing the audio from one or more tracks.

class AVAssetReaderTrackOutput

An object that defines an interface for reading media data from a single track of an asset reader's asset.

class AVAssetReaderSampleReferenceOutput

An object that defines an interface for reading sample references from a single asset track.

class AVAssetReaderVideoCompositionOutput

An object that reads video frames composited from the frames in one or more tracks of a reader's assets.

class AVAssetReaderOutput

An abstract class that defines an interface for reading a single collection of samples of a common media type from an asset reader object.

class AVAssetReaderOutputMetadataAdaptor

An object that defines an interface for reading metadata.

class AVAssetImageGenerator

An object that provides thumbnail or preview images of assets independently of playback.