In the built in apps for tvOS when you watch a video it shows information about that video when you swipe down. I can't find any information on how a developer can do this same thing. I'm sure it is designed to be possible as it says "Swipe down for info" Has anybody figured this out? I'm using AVPlayerViewController. Thanks.
These APIs create and control profiles for Apple TV devices, which make the Apple TV setup easier for your customers. With the set top box APIs, the setup flow highlights the customer's TV provider when they first set up their Apple TV.
As indicated by the alert, to enable Developer Mode go to Settings > Privacy & Security on the iOS device. Scroll down to the Developer Mode list item and navigate into it. To toggle Developer mode, use the “Developer Mode” switch. Tap the switch to enable Developer Mode.
An object that presents the visual contents of a player object.
Apple's new TV operating system will allow users to bring AirPods Pro and AirPods Max to listen to Apple's spatial audio. Apple advertises Spatial Audio as an immersive audio experience with multi-dimensional sound and clarity. Spatial Audio is a modern form of surround sound.
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;
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
In addition to Jeff's answer, this is the function I use to avoid repetivity:
private func setupMetadata(data: String, key: (NSCopying & NSObjectProtocol))->AVMutableMetadataItem{
let metadataItem = AVMutableMetadataItem()
metadataItem.locale = NSLocale.current
metadataItem.key = key
metadataItem.keySpace = AVMetadataKeySpaceCommon
metadataItem.value = data as (NSCopying & NSObjectProtocol)?
return metadataItem
}
and in use:
//in AVPlayerViewControler
//Suppose you have an already initialized avPlayerItem
avPlayerItem.externalMetadata.append(self.setupMetadata(data: "title of video", key: AVMetadataCommonKeyTitle as (NSCopying & NSObjectProtocol)))
avPlayerItem.externalMetadata.append(self.setupMetadata(data: "RugDealer", key: AVMetadataCommonKeyAuthor as (NSCopying & NSObjectProtocol)))
avPlayerItem.externalMetadata.append(self.setupMetadata(data: "Description of the video", key: AVMetadataCommonKeyDescription as (NSCopying & NSObjectProtocol)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With