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


class AVPlayerItemMetadataCollector : AVPlayerItemMediaDataCollector


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, you create an instance of AVPlayerItemMetadataCollector, configure its delegate object (see AVPlayerItemMetadataCollectorPushDelegate), and add it as a media data collector to the AVPlayerItem (see example).

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)
        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:) initializer.


Creating a Metadata Collector

init(identifiers: [String]?, classifyingLabels: [String]?)

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

func setDelegate(AVPlayerItemMetadataCollectorPushDelegate?, queue: DispatchQueue?)

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

var delegate: AVPlayerItemMetadataCollectorPushDelegate?

Accesses the metadata collector’s delegate object.

protocol AVPlayerItemMetadataCollectorPushDelegate

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

var delegateQueue: DispatchQueue?

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


Conforms To

See Also

Media Playback

class AVPlayer

An object that provides the interface to control the player’s transport behavior.

class AVQueuePlayer

A player used to play a number of items in sequence.

class AVPlayerLayer

An object that manages a player's visual output.

class AVPlayerItem

An object used to model the timing and presentation state of an asset played by the player.

class AVPlayerItemTrack

An object used to modify the presentation state of an asset track being presented by a player.

class AVSynchronizedLayer

An object used to synchronize with a specific player item.

class AVPlayerMediaSelectionCriteria

An object that specifies the preferred languages and media characteristics for a player.

class AVSampleBufferAudioRenderer

An object used to decompress audio and play compressed or uncompressed audio.

class AVSampleBufferDisplayLayer

An object that displays compressed or uncompressed video frames.

class AVSampleBufferRenderSynchronizer

An object used to synchronize multiple queued sample buffers to a single timeline.

class AVRouteDetector

An object that detects the presences of media playback routes.