tvOS AVPlayerViewController Video Info
The accepted answer is correct. We can use AVMutableMetadataItem
to provide video related information.
But if you need to have more options in player menu, it is better to create a UIViewController
with custom information and settings option [based on your requirement] and set it as AVPlayerViewController
's customInfoViewController
.
This is available from tvOS 11.0
Official apple docs on this: Apple Docs Link
To get the "Info" section to show up in the "Swipe down for info" pane in AVPlayerViewController
you create AVMutableMetadataItem
s with the AVMetadataKeySpaceCommon
keyspace and any of the following keys:
AVMetadataCommonKeyTitle
AVMetadataCommonKeyDescription
AVMetadataiTunesMetadataKeyContentRating
AVMetadataQuickTimeMetadataKeyGenre
and add them to the AVPlayerItem
's externalMetadata
array. In order for each AVMutableMetadataItem
to show up you must at least set the identifier
, extendedLanguageTag
, and value
properties. Here's an example:
let mediaItem = AVPlayerItem(URL: mediaURL)
let titleMetadataItem = AVMutableMetadataItem()
titleMetadataItem.locale = NSLocale.currentLocale()
titleMetadataItem.key = AVMetadataCommonKeyTitle
titleMetadataItem.keySpace = AVMetadataKeySpaceCommon
titleMetadataItem.value = "The Title"
let descriptionMetadataItem = AVMutableMetadataItem()
descriptionMetadataItem.locale = NSLocale.currentLocale()
descriptionMetadataItem.key = AVMetadataCommonKeyDescription
descriptionMetadataItem.keySpace = AVMetadataKeySpaceCommon
descriptionMetadataItem.value = "This is the description"
mediaItem.externalMetadata.append(titleMetadataItem)
mediaItem.externalMetadata.append(descriptionMetadataItem)
This isn't well-documented. This forum post was critical to figuring this out.
Objective-C example for @JenelEjercitoMyers:
AVPlayerItem *mediaItem = [[AVPlayerItem alloc] initWithURL:mediaURL];
AVMutableMetadataItem *titleMetadataItem = [[AVMutableMetadataItem alloc] init];
titleMetadataItem.locale = NSLocale.currentLocale;
titleMetadataItem.key = AVMetadataCommonKeyTitle;
titleMetadataItem.keySpace = AVMetadataKeySpaceCommon;
titleMetadataItem.value = @"The Title";
NSArray *externalMetadata = [[NSArray alloc] initWithObjects:titleMetadataItem, nil];
mediaItem.externalMetadata = externalMetadata;