<!--
{
  "documentType" : "article",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/retrieving-media-metadata",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Retrieving media metadata"
}
-->

# Retrieving media metadata

Load descriptive metadata for media assets and their tracks.

## Discussion

Media container formats provide metadata that describe their content. You can retrieve it to access information about the media such as the title, artwork, and creation date. AVFoundation models metadata values using the [`AVMetadataItem`](/documentation/AVFoundation/AVMetadataItem) class. A metadata item represents a single value like a movie’s description or poster image. This class provides a simple, consistent interface to work with metadata, regardless of the underlying container and metadata formats.

### Load an asset’s metadata

[`AVAsset`](/documentation/AVFoundation/AVAsset) provides several ways to access its metadata. You can retrieve all of its metadata by loading the value of its [`metadata`](/documentation/AVFoundation/AVPartialAsyncProperty/metadata-16qej) property. Alternatively, you can retrieve a subset of items that are common to all of the metadata formats it holds by loading the value of its [`commonMetadata`](/documentation/AVFoundation/AVPartialAsyncProperty/commonMetadata-3j3n4) property.

To retrieve format-specific collections of metadata, like [`iTunesMetadata`](/documentation/AVFoundation/AVMetadataFormat/iTunesMetadata) or [`quickTimeMetadata`](/documentation/AVFoundation/AVMetadataFormat/quickTimeMetadata), call an asset’s [`loadMetadata(for:completionHandler:)`](/documentation/AVFoundation/AVAsset/loadMetadata(for:completionHandler:)) method, passing it a specific [`AVMetadataFormat`](/documentation/AVFoundation/AVMetadataFormat) to load. The example below iterates over the [`availableMetadataFormats`](/documentation/AVFoundation/AVPartialAsyncProperty/availableMetadataFormats-4yiq8) an asset contains, and loads each format’s metadata items to process their values.

```swift
// A local or remote asset to inspect.
let asset = AVURLAsset(url: url)
for format in try await asset.load(.availableMetadataFormats) {
    let metadata = try await asset.loadMetadata(for: format)
    // Process the format-specific metadata collection.
    print("The available metadata format is \(metadata)")
}
```

### Filter a metadata collection

After you load a collection of metadata, you can filter it to specific values using the class methods of [`AVMetadataItem`](/documentation/AVFoundation/AVMetadataItem). The example below shows how to use the [`metadataItems(from:filteredByIdentifier:)`](/documentation/AVFoundation/AVMetadataItem/metadataItems(from:filteredByIdentifier:)) method to find items with an identifier of [`commonIdentifierTitle`](/documentation/AVFoundation/AVMetadataIdentifier/commonIdentifierTitle).

```swift
// Load the asset's metadata.
let metadata = try await asset.load(.metadata)
        
// Find the title in the common key space.
let titleItems = AVMetadataItem.metadataItems(from: metadata,
                                              filteredByIdentifier: .commonIdentifierTitle)
guard let item = titleItems.first else { return }
// Process the title item.
```

A metadata item’s filtering methods return collections of items instead of a single instance. In many cases, the returned collection contains a single element, but if the media contains localized metadata, or if you’re retrieving data from the common key space and the same value exists in multiple key spaces, the item returns a distinct value for each.

### Find specific values

Retrieve the data a metadata item holds by loading its [`value`](/documentation/AVFoundation/AVPartialAsyncProperty/value) property, which is an object that adopts the <doc://com.apple.documentation/documentation/Foundation/NSCopying> and <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol> protocols. You can manually cast the value to an appropriate type, but it’s safer and more convenient to use the metadata item’s type conversion properties. Instead of loading the [`value`](/documentation/AVFoundation/AVPartialAsyncProperty/value) property, load its [`stringValue`](/documentation/AVFoundation/AVPartialAsyncProperty/stringValue), [`numberValue`](/documentation/AVFoundation/AVPartialAsyncProperty/numberValue), [`dateValue`](/documentation/AVFoundation/AVPartialAsyncProperty/dateValue), or [`dataValue`](/documentation/AVFoundation/AVPartialAsyncProperty/dataValue) properties as appropriate to convert it to a specific type. For example, the code listing below shows how to retrieve the artwork associated with an iTunes music track as a data value:

```swift
// The collection of iTunes metadata.
let iTunesMetadata = try await asset.loadMetadata(for: .iTunesMetadata)

// Filter metadata to find the asset's artwork.
guard let artworkItem = AVMetadataItem.metadataItems(from: iTunesMetadata,
                                                     filteredByIdentifier: .iTunesMetadataCoverArt).first else { return }

// Retrieve a Data object that contains the image data.
guard let imageData = try await artworkItem.load(.dataValue) else { return }
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)