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 {
let title: String
let uri: String
let uri: String?
let startTime: Double
let endTime: Double
@ -11,14 +11,14 @@ struct Chapter {
guard json != nil else {
self.json = nil
self.title = ""
self.uri = ""
self.uri = nil
self.startTime = 0
self.endTime = 0
return
}
self.json = json
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.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 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)
}