Mac Developer Library

Developer

AV Foundation Framework Reference AVAsset Class Reference

Options
Deployment Target:

On This Page
Language:

AVAsset

AVAsset is an abstract class to represent timed audiovisual media such as videos and sounds. Each asset contains a collection of tracks that are intended to be presented or processed together, each of a uniform media type, including but not limited to audio, video, text, closed captions, and subtitles.

An AVAsset object 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 NSURLs 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.

Properties of assets as a whole are defined by AVAsset. Additionally, references to instances of AVAssetTrack representing tracks of the collection can be obtained, so that each of these can be examined independently.

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 items 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.

  • Returns an asset for inspection of a media resource.

    Declaration

    Swift

    convenience init(URL URL: NSURL)

    Objective-C

    + (instancetype)assetWithURL:(NSURL *)URL

    Parameters

    URL

    A URL that references a media resource.

    Return Value

    An instance of a subclass of AVAsset initialized with URL.

    Availability

    Available in OS X v10.7 and later.

  • Cancels the loading of all values for all observers.

    Declaration

    Swift

    func cancelLoading()

    Objective-C

    - (void)cancelLoading

    Discussion

    Deallocation of an instance of the asset implicitly invokes this method if any loading requests are still outstanding.

    Availability

    Available in OS X v10.7 and later.

  • A Boolean value that indicates whether the asset has protected content. (read-only)

    Declaration

    Swift

    var hasProtectedContent: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL hasProtectedContent

    Availability

    Available in OS X v10.7 and later.

  • Indicates whether the asset, or its URL, can be used to initialize an instance of AVPlayerItem. (read-only)

    Declaration

    Swift

    var playable: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isPlayable) BOOL playable

    Availability

    Available in OS X v10.7 and later.

  • A Boolean value that indicates whether the asset can be exported using AVAssetExportSession. (read-only)

    Declaration

    Swift

    var exportable: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isExportable) BOOL exportable

    Availability

    Available in OS X v10.7 and later.

  • A Boolean value that indicates whether the asset’s media data can be extracted using AVAssetReader. (read-only)

    Declaration

    Swift

    var readable: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isReadable) BOOL readable

    Availability

    Available in OS X v10.7 and later.

  • A Boolean value that indicates whether the asset can be used within a segment of an AVCompositionTrack object. (read-only)

    Declaration

    Swift

    var composable: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isComposable) BOOL composable

    Availability

    Available in OS X v10.7 and later.

  • naturalSize (OS X v10.8) Property

    The encoded or authored size of the visual portion of the asset. (read-only)

    Deprecation Statement

    Use the naturalSize and preferredTransform, as appropriate, of the asset’s video tracks instead (see also tracksWithMediaType:).

    Declaration

    Objective-C

    @property(nonatomic, readonly) CGSize naturalSize

    Availability

    Available in OS X v10.7 and later.

    Deprecated in OS X v10.8.

  • The natural rate at which the asset is to be played. (read-only)

    Declaration

    Swift

    var preferredRate: Float { get }

    Objective-C

    @property(nonatomic, readonly) float preferredRate

    Discussion

    This value is often, but not always, 1.0.

    Availability

    Available in OS X v10.7 and later.

  • The preferred transform to apply to the visual content of the asset for presentation or processing. (read-only)

    Declaration

    Swift

    var preferredTransform: CGAffineTransform { get }

    Objective-C

    @property(nonatomic, readonly) CGAffineTransform preferredTransform

    Discussion

    The value is often, but not always, the identity transform.

    Availability

    Available in OS X v10.7 and later.

  • The preferred volume at which the audible media of asset is to be played. (read-only)

    Declaration

    Swift

    var preferredVolume: Float { get }

    Objective-C

    @property(nonatomic, readonly) float preferredVolume

    Discussion

    This value is often, but not always, 1.0.

    Availability

    Available in OS X v10.7 and later.