chore: add chapter images
This commit is contained in:
parent
b225b0f800
commit
6cbc7cdc89
File diff suppressed because one or more lines are too long
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user