Is there a way to add custom information for AVPlayerViewController

I notice that in AVPlayerViewController there is a menu selection when I swipe down from the remote that shows Info/Chapter/Audio/etc options.


Is there a way to add more info in the Info section that's more custom like you do on the movie app from apple that has custom description of what the movie is about?

Answered by Technology Evangelist in 61400022

You can provide title, description, content rating, and an artwork image by setting the externalMetadata property of the AVPlayerItem with an array of AVMetadataItems. The data will then show up in the info panel.


You can also manage chapter markers in a similar way by setting the navigationMarkerGroups property.

Accepted Answer

You can provide title, description, content rating, and an artwork image by setting the externalMetadata property of the AVPlayerItem with an array of AVMetadataItems. The data will then show up in the info panel.


You can also manage chapter markers in a similar way by setting the navigationMarkerGroups property.

So if a full-screen AVMediaPlayerViewController is playing, for example, an.mp3 fille with appropriate externalMetadata array of AVMetadataItems, it will still appear as a black screen with a time-slider at the bottom unless the user opens the info panel? Can we open the info panel programatically?

It is not possible to open the info panel programatically. You might want to look at displaying some content using the contentOverlayView property of AVPlayerViewController. It's a non-interactive layer, but would avoid having a completely black screen.

Did you try to remove the following line?

artwork1.dataType = (__bridge NSString * _Nullable)(kCMMetadataBaseDataType_JPEG);


I also had trouble to display an image (PNG instead of JPG). But without specifying the dataType property everthing's working fine.


Here is my code (Swift):


if let image = UIImage(named: "myPNG") {
let artwork = AVMutableMetadataItem()
artwork.key = AVMetadataCommonKeyArtwork
artwork.keySpace = AVMetadataKeySpaceCommon
artwork.value = UIImagePNGRepresentation(image)
artwork.locale = NSLocale.currentLocale()
video.externalMetadata.append(artwork)
}

The properties that must be set for each metadata item are: identifier, extendedLanguageTag, and value

As long as you set those three, you should be good to go.

Thanks sergiou87.


Can you please file a bug at bugreporter.apple.com and include the content of the gist in the report?


Thanks!

Is there any reason why after doing so my info/metadata that I put in there is faded and hard to read?

I see the same thing, SerenadeX. It seems to be a bug with the Simulator. Works fine on the actual device.

I'm getting this compilation error: "Property 'externalMetadata' not found on object of type 'AVPlayerItem *'"


Using XCode 7.2 tvOS 9.1


This is the code:


NSMutableArray* items = [[NSMutableArray alloc] init];
AVMutableMetadataItem* item = [AVMutableMetadataItem metadataItem];
item.locale = NSLocale.currentLocale;
item.key = AVMetadataCommonKeyTitle;
item.keySpace = AVMetadataKeySpaceCommon;
item.value = @"Video 1";
[items addObject:item];
item = [AVMutableMetadataItem metadataItem];
item.locale = NSLocale.currentLocale;
item.key = AVMetadataQuickTimeMetadataKeyGenre;
item.keySpace = AVMetadataKeySpaceCommon;
item.value = @"Summary";
[items addObject:item];
playerItem.externalMetadata = items; //<-- Compilation error


Compilation error in the last line of code. Can't figure out what's wrong. Autocompletion in the XCode editor doesn't show externalMetadata, navigationMarkerGroups or interstitialTimeRanges. Any help would be appreciated.

That's very odd - I can't reproduce that particular issue on my end.


Are you including AVKit in that file? Note that these extensions on AVPlayerItem are part of the AVKit framework, not AVFoundation.


This sample code works fine for me. I'm using identifiers here rather than key and keySpace, which would be our recommendation:


- (void)setMetadata {
NSMutableArray* items = [[NSMutableArray alloc] init];
AVMutableMetadataItem* item = [AVMutableMetadataItem metadataItem];
item.locale = NSLocale.currentLocale;
item.identifier = AVMetadataCommonIdentifierTitle;
item.value = @"Video 1";
[items addObject:item];
item = [AVMutableMetadataItem metadataItem];
item.locale = NSLocale.currentLocale;
item.identifier = AVMetadataIdentifierQuickTimeMetadataGenre;
item.value = @"Summary";
[items addObject:item];
playerItem.externalMetadata = items;
}
Is there a way to add custom information for AVPlayerViewController
 
 
Q