---
title: "loadChapterMetadataGroups(bestMatchingPreferredLanguages:completionHandler:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avasset/loadchaptermetadatagroups(bestmatchingpreferredlanguages:completionhandler:)"
---

# loadChapterMetadataGroups(bestMatchingPreferredLanguages:completionHandler:)

Loads chapter metadata with a locale that best matches the list of preferred languages.

## Declaration

```swift
func loadChapterMetadataGroups(bestMatchingPreferredLanguages preferredLanguages: [String], completionHandler: @escaping @Sendable ([AVTimedMetadataGroup]?, (any Error)?) -> Void)
```

```swift
func loadChapterMetadataGroups(bestMatchingPreferredLanguages preferredLanguages: [String]) async throws -> [AVTimedMetadataGroup]
```

## Parameters

- `preferredLanguages`: An array of language identifiers in order of preference, each of which is an IETF BCP 47 (RFC 4646) language identifier. Call doc://com.apple.documentation/documentation/Foundation/Locale/preferredLanguages to retrieve the list of languates the user prefers.
- `completionHandler`: A callback that the system invokes after it finishes the loading request. It passes the completion handler the following parameters:

## Discussion

Discussion This method returns an array of AVTimedMetadataGroup objects asynchronously. Each object in the array contains an AVMetadataItem that represents the chapter’s title, and the metadata group’s timeRange value equals the time range of the chapter title item. The metadata group contains all chapter metadata, including items with the common key commonKeyArtwork, if such items are present. The system adds an AVMetadataItem with the specified common key to an existing AVTimedMetadataGroup object if the time range (timestamp and duration) of the metadata item and the metadata group overlap. The locales of such items don’t need to match the locale of the chapter titles. You can use the 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:) method.

## See Also

### Loading chapter metadata

- [availableChapterLocales](avfoundation/avpartialasyncproperty/availablechapterlocales.md)
- [loadChapterMetadataGroups(withTitleLocale:containingItemsWithCommonKeys:)](avfoundation/avasset/loadchaptermetadatagroups(withtitlelocale:containingitemswithcommonkeys:).md)
