Class

AVPlayerItemMetadataCollector

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

Declaration

@interface AVPlayerItemMetadataCollector : AVPlayerItemMediaDataCollector

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, 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).

// Adopts AVPlayerItemMetadataCollectorPushDelegate
@implementation PlaybackController
 
- (void)prepareToPlay:(NSURL *)url {
    self.metadataCollector = [[AVPlayerItemMetadataCollector alloc] init];
    [self.metadataCollector setDelegate:self queue:dispatch_get_main_queue()];
 
    self.playerItem = [AVPlayerItem playerItemWithURL:url];
    [self.playerItem addMediaDataCollector:self.metadataCollector];
 
    self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
}
 
- (void)metadataCollector:(AVPlayerItemMetadataCollector *)metadataCollector
didCollectDateRangeMetadataGroups:(NSArray<AVDateRangeMetadataGroup *> *)metadataGroups
       indexesOfNewGroups:(NSIndexSet *)indexesOfNewGroups
  indexesOfModifiedGroups:(NSIndexSet *)indexesOfModifiedGroups {
    // Process metadata
}
 
@end

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 initWithIdentifiers:classifyingLabels: initializer.

Topics

Creating a Metadata Collector

- initWithIdentifiers: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:

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

delegate

Accesses the metadata collector’s delegate object.

AVPlayerItemMetadataCollectorPushDelegate

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

delegateQueue

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

Relationships

See Also

Media Playback

AVPlayer

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

AVQueuePlayer

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

AVPlayerLayer

An object that manages a player's visual output.

AVPlayerItem

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

AVPlayerItemTrack

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

AVSynchronizedLayer

An object used to synchronize with a specific player item.

AVPlayerMediaSelectionCriteria

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

AVSampleBufferAudioRenderer

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

AVSampleBufferDisplayLayer

An object that displays compressed or uncompressed video frames.

AVSampleBufferRenderSynchronizer

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

AVRouteDetector

An object that detects the presences of media playback routes.