Use video thumbnails from API when possible
This commit is contained in:
parent
5a26739b78
commit
1ec85ca095
|
@ -184,15 +184,26 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
|||
}
|
||||
|
||||
func loadVideo() {
|
||||
let attachmentURL = self.attachment.url
|
||||
// todo: use a single dispatch queue
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let asset = AVURLAsset(url: attachmentURL)
|
||||
let generator = AVAssetImageGenerator(asset: asset)
|
||||
generator.appliesPreferredTrackTransform = true
|
||||
guard let image = try? generator.copyCGImage(at: .zero, actualTime: nil) else { return }
|
||||
self.source = .cgImage(attachmentURL, image)
|
||||
self.displayImage()
|
||||
if let previewURL = self.attachment.previewURL {
|
||||
attachmentRequest = ImageCache.attachments.get(previewURL, completion: { [weak self] (data, _ )in
|
||||
guard let self = self, let data = data else { return }
|
||||
DispatchQueue.main.async {
|
||||
self.attachmentRequest = nil
|
||||
self.source = .imageData(previewURL, data)
|
||||
self.displayImage()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let attachmentURL = self.attachment.url
|
||||
// todo: use a single dispatch queue
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let asset = AVURLAsset(url: attachmentURL)
|
||||
let generator = AVAssetImageGenerator(asset: asset)
|
||||
generator.appliesPreferredTrackTransform = true
|
||||
guard let image = try? generator.copyCGImage(at: .zero, actualTime: nil) else { return }
|
||||
self.source = .cgImage(attachmentURL, image)
|
||||
self.displayImage()
|
||||
}
|
||||
}
|
||||
|
||||
let playImageView = UIImageView(image: UIImage(systemName: "play.circle.fill"))
|
||||
|
|
Loading…
Reference in New Issue