Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tvOS AVPlayerViewController Video Info

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.

like image 783
Brian F Leighty Avatar asked Oct 22 '15 15:10

Brian F Leighty


People also ask

Does Apple TV have an API?

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.

How do you get to developer options on 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.

What is Avplayerlayer?

An object that presents the visual contents of a player object.

What is new in os15 Apple TV?

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.


3 Answers

To get the "Info" section to show up in the "Swipe down for info" pane in AVPlayerViewController you create AVMutableMetadataItems 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;
like image 130
Jeff Bowen Avatar answered Sep 26 '22 13:09

Jeff Bowen


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

enter image description here

Official apple docs on this: Apple Docs Link

like image 32
abhimuralidharan Avatar answered Sep 26 '22 13:09

abhimuralidharan


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)))
like image 26
kemicofa ghost Avatar answered Sep 23 '22 13:09

kemicofa ghost