<!--
{
  "availability" : [
    "iOS: 9.3.0 -",
    "iPadOS: 9.3.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.3 -",
    "tvOS: 9.2.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.3.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVPlayerItemMetadataCollector",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVPlayerItemMetadataCollector"
  },
  "title" : "AVPlayerItemMetadataCollector"
}
-->

# AVPlayerItemMetadataCollector

An object used to capture the date range metadata defined for an HTTP Live Streaming asset.

```
class AVPlayerItemMetadataCollector
```

## Overview

You can use the HLS `#EXT-X-DATERANGE` tag to define date range metadata in a media playlist. This tag is useful for defining timed metadata for interstitial regions such as advertisements, but can be used to define any timed metadata needed by your stream. To access this metadata when the stream is played using an [`AVPlayer`](/documentation/AVFoundation/AVPlayer), you create an instance of `AVPlayerItemMetadataCollector`, configure its delegate object (see [`AVPlayerItemMetadataCollectorPushDelegate`](/documentation/AVFoundation/AVPlayerItemMetadataCollectorPushDelegate)), and add it as a media data collector to the [`AVPlayerItem`](/documentation/AVFoundation/AVPlayerItem) (see example).

```swift
class PlaybackController: NSObject, AVPlayerItemMetadataCollectorPushDelegate {
    
    let player = AVPlayer()
    var playerItem: AVPlayerItem!
    var metadataCollector: AVPlayerItemMetadataCollector!
    
    func prepareToPlay(url: URL) {
        metadataCollector = AVPlayerItemMetadataCollector()
        metadataCollector.setDelegate(self, queue: DispatchQueue.main)
        
        playerItem = AVPlayerItem(url: url)
        playerItem.add(metadataCollector)
        
        player.replaceCurrentItem(with: playerItem)
    }
    
    func metadataCollector(_ metadataCollector: AVPlayerItemMetadataCollector,
                           didCollect metadataGroups: [AVDateRangeMetadataGroup],
                           indexesOfNewGroups: IndexSet,
                           indexesOfModifiedGroups: IndexSet) {
        // Process metadata
    }
}
```

Creating an `AVPlayerItemMetadataCollector` as shown in the example, will capture all `#EXT-X-DATERANGE` metadata defined in your stream. If you would like to filter the output to only the metadata of interest, you can create an instance to filter by identifier and/or classifying labels using the [`init(identifiers:classifyingLabels:)`](/documentation/AVFoundation/AVPlayerItemMetadataCollector/init(identifiers:classifyingLabels:)) initializer.

## Topics

### Creating a metadata collector

[`init(identifiers:classifyingLabels:)`](/documentation/AVFoundation/AVPlayerItemMetadataCollector/init(identifiers:classifyingLabels:))

Creates a metadata collector to access a stream’s metadata groups matching the specified array of identifiers and classifying labels.

### Accessing the delegate and callback queue

[`setDelegate(_:queue:)`](/documentation/AVFoundation/AVPlayerItemMetadataCollector/setDelegate(_:queue:))

Sets the delegate and a dispatch queue on which the delegate will be called.

[`delegate`](/documentation/AVFoundation/AVPlayerItemMetadataCollector/delegate)

Accesses the metadata collector’s delegate object.

[`AVPlayerItemMetadataCollectorPushDelegate`](/documentation/AVFoundation/AVPlayerItemMetadataCollectorPushDelegate)

A protocol you implement to receive metadata callbacks from a player item metadata collector.

[`delegateQueue`](/documentation/AVFoundation/AVPlayerItemMetadataCollector/delegateQueue)

The dispatch queue on which the delegate’s methods are called.



---

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)