The abstract class used to model timed audiovisual media such as videos and sounds.


An AVAsset defines the collective properties of the tracks that comprise the asset. (You can access the instances of AVAssetTrack representing tracks of the collection, so you can examine each of these independently if you need to.)

You often instantiate an asset using AVURLAsset—a concrete subclass of AVAsset—with URLs that refer to audiovisual media resources, such as streams (including HTTP live streams), QuickTime movie files, MP3 files, and files of other types. You can also instantiate an asset using other concrete subclasses that extend the basic model for audiovisual media in useful ways, as AVComposition does for temporal editing.

Because of the nature of timed audiovisual media, upon successful initialization of an asset some or all of the values for its keys may not be immediately available. The value of any key can be requested at any time, and asset always returns its value synchronously, although it may have to block the calling thread in order to do so. In order to avoid blocking, you can register your interest in particular keys and to become notified when their values become available. For further details, see AVAsynchronousKeyValueLoading.

To play an instance of AVAsset, initialize an instance of AVPlayerItem with it, use the player item to set up its presentation state (such as whether only a limited timeRange of the asset should be played, etc.), and provide the player item to an AVPlayer object according to whether the item is to be played by itself or together with a collection of other items.

You can insert AVAsset objects into an AVMutableComposition object in order to assemble audiovisual constructs from one or more source assets.

Subclassing Notes

It is not currently possible to subclass AVAsset to handle streaming protocols or file formats that are not supported by the framework.


Creating an Asset

init(url: URL)

Returns an asset for inspection of a media resource.

Loading Data

func cancelLoading()

Cancels the loading of all values for all observers.

Inspecting an Asset

var duration: CMTime

The duration of the asset.

var providesPreciseDurationAndTiming: Bool

A Boolean value that indicates whether the asset provides precise timing.

var creationDate: AVMetadataItem?

A value that indicates the creation date of the asset.

var preferredRate: Float

The natural rate at which the asset is to be played.

var preferredTransform: CGAffineTransform

The preferred transform to apply to the visual content of the asset for presentation or processing.

var preferredVolume: Float

The preferred volume at which the audible media of the asset is to be played.

Determining Usability

The usability properties have a value of true when the indicated operation can be performed, even if only true under a specific set of conditions. These properties only return false when there is no condition under which the associated operation can be performed.

var isPlayable: Bool

A Boolean value that indicates whether the asset, or its URL, can be used to initialize an instance of AVPlayerItem.

var isExportable: Bool

A Boolean value that indicates whether the asset can be exported using AVAssetExportSession.

var isReadable: Bool

A Boolean value that indicates whether the asset’s media data can be extracted using AVAssetReader.

var isComposable: Bool

A Boolean value that indicates whether the asset can be used within a segment of an AVCompositionTrack object.

var hasProtectedContent: Bool

A Boolean value that indicates whether the asset has protected content.

var isCompatibleWithAirPlayVideo: Bool

A Boolean value that indicates whether the asset is compatible with AirPlay Video.

var isCompatibleWithSavedPhotosAlbum: Bool

A Boolean value that indicates whether the asset can be written to the Saved Photos album.

Accessing Tracks

var tracks: [AVAssetTrack]

The collection of all tracks contained by the asset.

var trackGroups: [AVAssetTrackGroup]

An array containing all of the track groups in the asset.

func track(withTrackID: CMPersistentTrackID)

Returns the track with a specified track ID.

func tracks(withMediaType: AVMediaType)

Returns an array of the asset tracks of the asset that presents media of a specified type.

func tracks(withMediaCharacteristic: AVMediaCharacteristic)

Returns an array of asset tracks of the asset that presents media with a specified characteristic.

func unusedTrackID()

Returns an ID that's unused by any of the tracks in the asset.

Accessing Metadata

var lyrics: String?

The lyrics of the asset, in a language suitable for the current locale.

var metadata: [AVMetadataItem]

An array of metadata items for all metadata identifiers for which a value is available.

var commonMetadata: [AVMetadataItem]

An array of metadata items for each common metadata key for which a value is available.

var availableMetadataFormats: [AVMetadataFormat]

An array of strings, each representing a metadata format that’s available to the asset.

func metadata(forFormat: AVMetadataFormat)

Returns an array of AVMetadataItem objects—one for each metadata item in the container of the specified format.

Using Chapter Metadata

var availableChapterLocales: [Locale]

The locales available for chapter metadata in the asset.

func chapterMetadataGroups(withTitleLocale: Locale, containingItemsWithCommonKeys: [AVMetadataKey]?)

Returns an array of chapters with a given title locale and containing specified keys.

func chapterMetadataGroups(bestMatchingPreferredLanguages: [String])

Returns an array of chapters whose locale best matches the list of preferred languages.

Finding Media Selections

var preferredMediaSelection: AVMediaSelection

The default media selections for this asset’s media selection groups.

var availableMediaCharacteristicsWithMediaSelectionOptions: [AVMediaCharacteristic]

An array of media characteristics for which a media selection option is available.

func mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristic)

Returns an AVMediaSelectionGroup object that contains one or more options with the specified media characteristic.

Managing Reference Restrictions

var referenceRestrictions: AVAssetReferenceRestrictions

The reference restrictions being used by the receiver.

Working with Fragmented Movies

var canContainFragments: Bool

A Boolean value that indicates whether the asset is capable of being extended by fragments.

var containsFragments: Bool

A Boolean value that indicates whether the asset is extended by at least one movie fragment.

var overallDurationHint: CMTime

A Boolean value that indicates the total duration of fragments that either exist now or may be appended in the future in order to extend the duration of the asset.

Specifying Media Characteristics

struct AVMediaCharacteristic

Options for specifying the characteristics of media types.

See Also

Media Assets

class AVAssetTrack

An object that provides the track-level inspection interface for an asset’s media tracks.

Asset Manipulation

Retrieve assets to be used for playback or to get information about an asset; for example, an asset's playing time.

Asset File Import and Export

Import existing media samples from the file system; export new, modified, or existing media samples to the file system.