Understand how assets are used as the building blocks for media players.
Many of AVFoundation’s key features and capabilities relate to playing and processing media assets. The framework models assets by using the
AVAsset class, which is an abstract, immutable type representing a single media resource. It provides a composite view of a media asset, modeling the static aspects of the media as a whole. An instance of
AVAsset can model local file-based media, such as a QuickTime movie or an MP3 audio file, but can also represent an asset progressively downloaded from a remote host or streamed using HTTP Live Streaming (HLS).
AVAsset simplifies working with media in two important ways. First, it provides a level of independence from the media format. It gives you a consistent interface for managing and interacting with your media regardless of its underlying type. The details of working with container formats and codec types are left to the framework, leaving you to focus on how you want to use those assets in your app.
AVAsset provides a level of independence from the media’s location. You create an asset instance by initializing it with the media’s URL. This could be a local URL, such as one contained within your app bundle or elsewhere on the file system, or it could be a resource, such as an HLS stream hosted on a remote server. In either case, the framework performs the work necessary to efficiently retrieve and load the media in a timely manner on your behalf. Removing the burdens of dealing with media formats and locations greatly simplifies working with audiovisual media.
AVAsset is a container object composed of one or more instances of
AVAsset, which models the asset’s uniformly typed media streams. The most commonly used track types are audio and video tracks, but
AVAsset also models other supplementary tracks, such as closed captions, subtitles, and timed metadata.
You retrieve an asset’s collection of tracks using its
tracks property. In many cases, you’ll want to perform operations on a subset of an asset’s tracks rather than on its complete collection. In these cases,
AVAsset also provides methods to retrieve subsets of tracks based on criteria such as identifier, media type, or characteristic.