feat(tvos): add custom image metadata option for tvos and add missing types for custom metadata properties (#3280)

* fix: add typescript types for custom metadata properties
* chore: add possibility to override image metadata of video playback

---------

Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com>
This commit is contained in:
Konstantin
2023-10-07 15:14:10 +02:00
committed by GitHub
parent 067adde124
commit a855284d8d
9 changed files with 48 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ struct VideoSource {
let title: String?
let subtitle: String?
let description: String?
let customImageUri: String?
let json: NSDictionary?
@@ -29,6 +30,7 @@ struct VideoSource {
self.title = nil
self.subtitle = nil
self.description = nil
self.customImageUri = nil
return
}
self.json = json
@@ -43,5 +45,6 @@ struct VideoSource {
self.title = json["title"] as? String
self.subtitle = json["subtitle"] as? String
self.description = json["description"] as? String
self.customImageUri = json["customImageUri"] as? String
}
}

View File

@@ -330,4 +330,15 @@ enum RCTVideoUtils {
item.extendedLanguageTag = "und"
return item.copy() as! AVMetadataItem
}
static func createImageMetadataItem(imageUri: String) -> Data? {
if let uri = URL(string: imageUri),
let imgData = try? Data(contentsOf: uri),
let image = UIImage(data: imgData),
let pngData = image.pngData() {
return pngData
}
return nil
}
}

View File

@@ -408,6 +408,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
mapping[.commonIdentifierDescription] = description
}
if let customImageUri = _source?.customImageUri,
let imageData = RCTVideoUtils.createImageMetadataItem(imageUri: customImageUri) {
mapping[.commonIdentifierArtwork] = imageData
}
if #available(iOS 12.2, *), !mapping.isEmpty {
playerItem.externalMetadata = RCTVideoUtils.createMetadataItems(for: mapping)
}