Update artwork using URLSession

This commit is contained in:
Arkadiusz Fal 2022-06-26 23:28:03 +02:00
parent 950a4459e8
commit 446e847860

View File

@ -585,23 +585,26 @@ final class PlayerModel: ObservableObject {
func updateCurrentArtwork() {
guard let video = currentVideo,
let thumbnailURL = video.thumbnailURL(quality: .medium),
let thumbnailData = try? Data(contentsOf: thumbnailURL)
let thumbnailURL = video.thumbnailURL(quality: .medium)
else {
return
}
#if os(macOS)
let image = NSImage(data: thumbnailData)
#else
let image = UIImage(data: thumbnailData)
#endif
if image.isNil {
let task = URLSession.shared.dataTask(with: thumbnailURL) { [weak self] thumbnailData, _, _ in
guard let thumbnailData = thumbnailData else {
return
}
currentArtwork = MPMediaItemArtwork(boundsSize: image!.size) { _ in image! }
#if os(macOS)
guard let image = NSImage(data: thumbnailData) else { return }
#else
guard let image = UIImage(data: thumbnailData) else { return }
#endif
self?.currentArtwork = MPMediaItemArtwork(boundsSize: image.size) { _ in image }
}
task.resume()
}
func toggleFullscreen(_ isFullScreen: Bool) {