AVAsynchronousKeyValueLoading Protocol Reference
| Framework | /System/Library/Frameworks/AVFoundation.framework/ |
| Availability | Available in iOS 4.0 and later. |
| Declared in | AVAsynchronousKeyValueLoading.h |
Overview
The AVAsynchronousKeyValueLoading protocol defines methods that let you use an AVAsset or AVAssetTrack object without blocking a thread. Using methods in the protocol, you can find out the current status of a key (for example, whether the corresponding value has been loaded); and ask the object to load values asynchronously, informing you when the operation has completed.
Because of the nature of timed audiovisual media, successful initialization of an asset does not necessarily mean that all its data is immediately available. Instead, an asset will wait to load data until an operation is performed on it (for example, directly invoking any relevantAVAsset methods, playback via an AVPlayerItem object, export using AVAssetExportSession, reading using an instance of AVAssetReader, and so on). This means that 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, you can:
First, determine whether the value for a given key is available using
statusOfValueForKey:error:.If a value has not been loaded yet, you can ask for to load one or more values and be notified when they become available using
loadValuesAsynchronouslyForKeys:completionHandler:.
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 filesystem), slow I/O may require AVAsset to block before returning their values. Although blocking may be acceptable in cases in which you are preparing assets on background threads or in operation queues, in all cases in which blocking should be avoided you should use loadValuesAsynchronouslyForKeys:completionHandler:.
Instance Methods
loadValuesAsynchronouslyForKeys:completionHandler:
Tells the asset to load the values of any of the specified keys that are not already loaded. (required)
Parameters
- keys
An array containing the required keys.
A key is an instance of
NSString.- handler
The block to be invoked when loading succeeds, fails, or is cancelled.
Discussion
The completion handler will be invoked exactly once per invocation of this method:
Synchronously if an I/O error or other format-related error occurs immediately.
Asynchronously at a subsequent time if a loading error occurs at a later stage of processing, or if
cancelLoadingis invoked on anAVAssetinstance.
The completion states of the keys you specify in keys are not necessarily the same—some may be loaded, and others may have failed. You must check the status of each key individually.
If you want to receive error reporting for loading that’s still pending, you can call this method at any time—even after an asset has begun to load data for operations in progress or already completed. If a fatal error has already occurred, the completion handler is invoked synchronously.
Availability
- Available in iOS 4.0 and later.
See Also
Declared In
AVAsynchronousKeyValueLoading.hstatusOfValueForKey:error:
Reports whether the value for a given key is immediately available without blocking. (required)
Parameters
- key
The key whose status you want.
- key
If the status of the value for the key is
AVKeyValueStatusFailed, upon return contains anNSErrorobject that describes the failure that occurred.
Return Value
The current loading status of the value for key. For possible values, see “Protocol Methods.”
Discussion
You use this method to determine the availability of the value for a key. This method does not cause an asset to load the value of a key that’s not yet available. To request values for keys that may not already be loaded without blocking, use loadValuesAsynchronouslyForKeys:completionHandler: and wait for invocation of the completion handler to be informed of availability.
Availability
- Available in iOS 4.0 and later.
Declared In
AVAsynchronousKeyValueLoading.hConstants
AVKeyValueStatus
A type to specify the load status of a given property.
typedef NSInteger AVKeyValueStatus;
Discussion
For possible values, see “Key Loading Status.”
Availability
- Available in iOS 4.0 and later.
Declared In
AVAsynchronousKeyValueLoading.hKey Loading Status
Constants to indicate the load status of a property.
enum {
AVKeyValueStatusUnknown,
AVKeyValueStatusLoading,
AVKeyValueStatusLoaded,
AVKeyValueStatusFailed,
AVKeyValueStatusCancelled
};
Constants
AVKeyValueStatusUnknownIndicates that the property status is unknown.
Available in iOS 4.0 and later.
Declared in
AVAsynchronousKeyValueLoading.h.AVKeyValueStatusLoadingIndicates that the property is not fully loaded.
Available in iOS 4.0 and later.
Declared in
AVAsynchronousKeyValueLoading.h.AVKeyValueStatusLoadedIndicates that the property is ready for use.
Available in iOS 4.0 and later.
Declared in
AVAsynchronousKeyValueLoading.h.AVKeyValueStatusFailedIndicates that the attempt to load the property failed.
Available in iOS 4.0 and later.
Declared in
AVAsynchronousKeyValueLoading.h.AVKeyValueStatusCancelledIndicates that the attempt to load the property was cancelled.
Available in iOS 4.0 and later.
Declared in
AVAsynchronousKeyValueLoading.h.
Discussion
See also statusOfValueForKey:error:.
© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-05-25)