mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Download audio artwork
This commit is contained in:
parent
e73072e224
commit
56441b5958
1 changed files with 25 additions and 0 deletions
|
|
@ -258,6 +258,7 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
if let itemID = itemAudioProperties?.itemID {
|
||||
Task {
|
||||
self.document = try? await downloadSpeechFile(itemID: itemID, priority: .high)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
let synthesizer = SpeechSynthesizer(appEnvironment: self.appEnvironment, networker: self.networker, document: self.document!)
|
||||
self.durations = synthesizer.estimatedDurations(forSpeed: self.playbackRate)
|
||||
|
|
@ -484,6 +485,26 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
MPNowPlayingInfoCenter.default().nowPlayingInfo = [:]
|
||||
}
|
||||
|
||||
func downloadAndSetArtwork() async {
|
||||
if let pageId = itemAudioProperties?.itemID, let imageURL = itemAudioProperties?.imageURL {
|
||||
if let result = try? await URLSession.shared.data(from: imageURL) {
|
||||
if let downloadedImage = UIImage(data: result.0) {
|
||||
let artwork = MPMediaItemArtwork(boundsSize: downloadedImage.size, requestHandler: { _ -> UIImage in
|
||||
downloadedImage
|
||||
})
|
||||
DispatchQueue.main.async {
|
||||
if pageId == self.itemAudioProperties?.itemID {
|
||||
if var nowPlaying = MPNowPlayingInfoCenter.default().nowPlayingInfo {
|
||||
nowPlaying[MPMediaItemPropertyArtwork] = artwork
|
||||
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlaying
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setupRemoteControl() {
|
||||
UIApplication.shared.beginReceivingRemoteControlEvents()
|
||||
|
||||
|
|
@ -538,6 +559,10 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
}
|
||||
return .commandFailed
|
||||
}
|
||||
|
||||
Task {
|
||||
await downloadAndSetArtwork()
|
||||
}
|
||||
}
|
||||
|
||||
func downloadSpeechFile(itemID: String, priority: DownloadPriority) async throws -> SpeechDocument? {
|
||||
|
|
|
|||
Loading…
Reference in a new issue