I’m trying to display Info on an AVPlayerController dropdown. I’m following exactly what they show in WWDC, adding metadata to the playerItem. Everything is showing up ok, except for the artwork image. What’s strange is that it seems to add the image to the info view, but then hides it. There’s a space where the image should be but nothing shows. It does show up on the tv remote app though, so I know I’m adding it correctly. Here’s my code:
let playerItem: AVPlayerItem = AVPlayerItem(asset: avasset)
var allItems: [AVMetadataItem] = []
allItems.append(self.metadataItem(identifier: AVMetadataCommonIdentifierTitle, value: asset.title as (NSCopying & NSObjectProtocol)?)!)
if let desc = asset.desc {
allItems.append(self.metadataItem(identifier: AVMetadataCommonIdentifierDescription, value: desc as (NSCopying & NSObjectProtocol)?)!)
}
if let image = self.thumbImage, let artworkItem = self.metadataArtworkItem(image: image) {
allItems.append(artworkItem)
}
playerItem.externalMetadata = allItems
self.setupPlayerItem(playerItem)
The methods used to create the metadataItem:
func metadataItem(identifier: String, value: (NSCopying & NSObjectProtocol)?) -> AVMetadataItem? {
if let actualValue = value {
let item = AVMutableMetadataItem()
item.value = actualValue
item.identifier = identifier
item.extendedLanguageTag = "und"
return item.copy() as? AVMetadataItem
}
return nil
}
func metadataArtworkItem(image: UIImage) -> AVMetadataItem? {
let item = AVMutableMetadataItem()
item.value = UIImagePNGRepresentation(image) as (NSCopying & NSObjectProtocol)?
item.dataType = kCMMetadataBaseDataType_PNG as String
item.identifier = AVMetadataCommonIdentifierArtwork
item.extendedLanguageTag = "und"
return item.copy() as? AVMetadataItem
}
So it turns out that if the AVMetadataCommonIdentifierDescription
item is nil or an empty string, the image gets hidden. All I had to do to fix it was set the description to " " if there's not text to show. I'm going to file a bug with apple on this because that's obviously not normal.