<!--
{
  "availability" : [
    "iOS: 6.0.0 - 16.0.0",
    "iPadOS: 6.0.0 - 16.0.0",
    "macCatalyst: 13.1.0 - 16.0.0",
    "macOS: 10.8.0 - 13.0.0",
    "tvOS: 9.0.0 - 16.0.0",
    "watchOS: 1.0.0 - 9.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVAsset/chapterMetadataGroups(bestMatchingPreferredLanguages:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAsset(im)chapterMetadataGroupsBestMatchingPreferredLanguages:"
  },
  "title" : "chapterMetadataGroups(bestMatchingPreferredLanguages:)"
}
-->

# chapterMetadataGroups(bestMatchingPreferredLanguages:)

Returns an array of chapters with a locale that best matches the list of preferred languages.

```
func chapterMetadataGroups(bestMatchingPreferredLanguages preferredLanguages: [String]) -> [AVTimedMetadataGroup]
```

## Parameters

`preferredLanguages`

An array of BCP 47 language identifier strings. The order of the identifiers in the array reflects the preferred language order, with the most preferred language being first in the array. Typically, you pass the user’s preferred languages by retrieving this array from the <doc://com.apple.documentation/documentation/Foundation/NSLocale/preferredLanguages> class method of <doc://com.apple.documentation/documentation/Foundation/NSLocale>.

## Return Value

An array of [`AVTimedMetadataGroup`](/documentation/AVFoundation/AVTimedMetadataGroup) objects.

## Discussion

Each object in the returned array contains an [`AVMetadataItem`](/documentation/AVFoundation/AVMetadataItem) object representing the chapter title. The time range property of the [`AVTimedMetadataGroup`](/documentation/AVFoundation/AVTimedMetadataGroup) object is equal to the time range of the chapter title item.

The metadata group contains all chapter metadata, including items with the common key [`commonKeyArtwork`](/documentation/AVFoundation/AVMetadataKey/commonKeyArtwork), if such items are present. The system adds an [`AVMetadataItem`](/documentation/AVFoundation/AVMetadataItem) with the specified common key to an existing [`AVTimedMetadataGroup`](/documentation/AVFoundation/AVTimedMetadataGroup) object if the time range (timestamp and duration) of the metadata item and the metadata group overlap. The locale of such items don’t need to match the locale of the chapter titles.

You can use the [`metadataItems(from:filteredAndSortedAccordingToPreferredLanguages:)`](/documentation/AVFoundation/AVMetadataItem/metadataItems(from:filteredAndSortedAccordingToPreferredLanguages:)) method to further filter the metadata items in each group. You can also filter the returned items based on locale using the [`metadataItems(from:with:)`](/documentation/AVFoundation/AVMetadataItem/metadataItems(from:with:)) method.

This method is callable without blocking the current thread after you’ve asynchronously loaded the [`availableChapterLocales`](/documentation/AVFoundation/AVAsset/availableChapterLocales) property.

---

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)