chore: add chapter images

This commit is contained in:
Konstantin Späth 2023-08-14 00:16:41 +02:00
parent b225b0f800
commit 6cbc7cdc89
3 changed files with 21 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
struct Chapter { struct Chapter {
let title: String let title: String
let uri: String let uri: String?
let startTime: Double let startTime: Double
let endTime: Double let endTime: Double
@ -11,14 +11,14 @@ struct Chapter {
guard json != nil else { guard json != nil else {
self.json = nil self.json = nil
self.title = "" self.title = ""
self.uri = "" self.uri = nil
self.startTime = 0 self.startTime = 0
self.endTime = 0 self.endTime = 0
return return
} }
self.json = json self.json = json
self.title = json["title"] as? String ?? "" self.title = json["title"] as? String ?? ""
self.uri = json["uri"] as? String ?? "" self.uri = json["uri"] as? String
self.startTime = json["startTime"] as? Double ?? 0 self.startTime = json["startTime"] as? Double ?? 0
self.endTime = json["endTime"] as? Double ?? 0 self.endTime = json["endTime"] as? Double ?? 0
} }

View File

@ -429,6 +429,20 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
let endTime = CMTime(seconds: chapter.endTime, preferredTimescale: timescale) let endTime = CMTime(seconds: chapter.endTime, preferredTimescale: timescale)
let timeRange = CMTimeRangeFromTimeToTime(start: startTime, end: endTime) let timeRange = CMTimeRangeFromTimeToTime(start: startTime, end: endTime)
// Image
if let imgUri = chapter.uri,
let uri = URL(string: imgUri),
let imgData = try? Data(contentsOf: uri),
let image = UIImage(data: imgData),
let pngData = image.pngData()
{
let imageItem = createMetadataItem(for: .commonIdentifierArtwork, value: pngData)
metadata.append(imageItem)
print("Image added")
} else {
print("Something went wrong")
}
return AVTimedMetadataGroup(items: metadata, timeRange: timeRange) return AVTimedMetadataGroup(items: metadata, timeRange: timeRange)
} }