Hi,
we're trying to set a custom thumbnail image from URL to an AVPlayer on our iOS app. We're trying to use external metadata of a AVPlayerItem, but it doesn't work.
let thumbailData = // image jpg data downloaded from internet
let videoUrl = // HLS video url
// AVURLAsset creation with HLS url
let avAsset = AVURLAsset(url: videoUrl)
// AVPlayerItem with AVURLAsset we've just created
let avPlayerItem = AVPlayerItem(asset: avAsset)
// retrieve external metadatas of AVPlayerItem
var metadata = avPlayerItem.externalMetadata
// Creation new metadata for thumbnail
let thumbnailMetadata = AVMutableMetadataItem()
thumbnailMetadata.keySpace = AVMetadataKeySpace.common
thumbnailMetadata.key = AVMetadataKey.commonKeyArtwork as NSString
thumbnailMetadata.identifier = AVMetadataIdentifier.commonIdentifierArtwork
thumbnailMetadata.dataType = kCMMetadataBaseDataType_JPEG as String
thumbnailMetadata.value = thumbnailData as NSData
thumbnailMetadata.extendedLanguageTag = "und" as String
if let metadataItem = thumbnailMetadata.copy() as? AVMetadataItem {
metadata.append(metadataItem)
}
// AVPlayer creation
let player = AVPlayer(playerItem: avPlayerItem)
// set player on AVPlayerViewController
playerVc.player = player
Any suggestion? Is it the right way to reach our goal?
Thank you