Methods you can implement to use an asset or asset track without blocking the calling thread.
- iOS 4.0+
- macOS 10.7+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 6.0+
This protocol includes methods you can use to find out the status of a key—any property of a class that uses asynchronous key value loading. For example, you can find out whether the value of a key has been loaded. You can also ask the object to load its values asynchronously and inform you when the operation has completed.
Because of the nature of timed audiovisual media, successful initialization of an asset doesn't necessarily mean that all of its data is immediately available. Instead, an asset waits to load its data until an operation is performed on it (for example, directly invoking any relevant
AVAsset methods, playback via an
AVPlayer object, export using
AVAsset, reading using an instance of
AVAsset, and so on). Although you can request the value of any key at any time, and its value will be returned synchronously, the calling thread may be blocked until the request can be satisfied. To avoid blocking:
If a value hasn't yet been loaded, use the
loadmethod to ask the asset to asynchronously load one or more of its values and notify you when they become available.
Values Asynchronously(for Keys: completion Handler:)
Determine whether the value for a given key is available using the
Of Value(for Key: error:)
The following example shows how to asynchronously load an asset’s
Even for use cases that may typically support ready access to some keys (such as for assets initialized with URLs for files in the local file system), slow I/O may require
AVAsset to block before returning the key's values. Although blocking may be acceptable for macOS clients if you're preparing assets on background threads or in operation queues, when blocking should be avoided, use the
load method. iOS and tvOS applications should always load values asynchronously using that method because blocking I/O requests may result in a termination of media services.