mirror of
https://github.com/yattee/yattee.git
synced 2024-12-24 14:33:40 +00:00
Update artwork using URLSession
This commit is contained in:
parent
950a4459e8
commit
446e847860
@ -585,23 +585,26 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
func updateCurrentArtwork() {
|
func updateCurrentArtwork() {
|
||||||
guard let video = currentVideo,
|
guard let video = currentVideo,
|
||||||
let thumbnailURL = video.thumbnailURL(quality: .medium),
|
let thumbnailURL = video.thumbnailURL(quality: .medium)
|
||||||
let thumbnailData = try? Data(contentsOf: thumbnailURL)
|
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(macOS)
|
let task = URLSession.shared.dataTask(with: thumbnailURL) { [weak self] thumbnailData, _, _ in
|
||||||
let image = NSImage(data: thumbnailData)
|
guard let thumbnailData = thumbnailData else {
|
||||||
#else
|
|
||||||
let image = UIImage(data: thumbnailData)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if image.isNil {
|
|
||||||
return
|
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) {
|
func toggleFullscreen(_ isFullScreen: Bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user