mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 23:20:35 +02:00
Merge pull request #389 from ronaldheft/ios-bug-artwork
Fix local cover images not used on iOS
This commit is contained in:
commit
81a8203cca
3 changed files with 27 additions and 27 deletions
|
@ -39,14 +39,18 @@ class LocalLibraryItem: Object, Codable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var coverContentUrl: String? {
|
var coverUrl: URL? {
|
||||||
if let path = self._coverContentUrl {
|
if let path = self._coverContentUrl {
|
||||||
return AbsDownloader.itemDownloadFolder(path: path)!.absoluteString
|
return AbsDownloader.itemDownloadFolder(path: path)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var coverContentUrl: String? {
|
||||||
|
return self.coverUrl?.absoluteString
|
||||||
|
}
|
||||||
|
|
||||||
var isBook: Bool { self.mediaType == "book" }
|
var isBook: Bool { self.mediaType == "book" }
|
||||||
var isPodcast: Bool { self.mediaType == "podcast" }
|
var isPodcast: Bool { self.mediaType == "podcast" }
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class PlayerHandler {
|
||||||
Task { await PlayerProgress.shared.syncToServer() }
|
Task { await PlayerProgress.shared.syncToServer() }
|
||||||
|
|
||||||
// Set now playing info
|
// Set now playing info
|
||||||
NowPlayingInfo.shared.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, artworkUrl: session.coverPath, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil))
|
NowPlayingInfo.shared.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil))
|
||||||
|
|
||||||
// Create the audio player
|
// Create the audio player
|
||||||
player = AudioPlayer(sessionId: sessionId, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
player = AudioPlayer(sessionId: sessionId, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||||
|
|
|
@ -11,15 +11,22 @@ import MediaPlayer
|
||||||
struct NowPlayingMetadata {
|
struct NowPlayingMetadata {
|
||||||
var id: String
|
var id: String
|
||||||
var itemId: String
|
var itemId: String
|
||||||
var artworkUrl: String?
|
|
||||||
var title: String
|
var title: String
|
||||||
var author: String?
|
var author: String?
|
||||||
var series: String?
|
var series: String?
|
||||||
|
|
||||||
var coverUrl: URL? {
|
var coverUrl: URL? {
|
||||||
guard let config = Store.serverConfig else { return nil }
|
if self.isLocal {
|
||||||
guard let url = URL(string: "\(config.address)/api/items/\(itemId)/cover?token=\(config.token)") else { return nil }
|
guard let item = Database.shared.getLocalLibraryItem(byServerLibraryItemId: self.itemId) else { return nil }
|
||||||
return url
|
return item.coverUrl
|
||||||
|
} else {
|
||||||
|
guard let config = Store.serverConfig else { return nil }
|
||||||
|
guard let url = URL(string: "\(config.address)/api/items/\(itemId)/cover?token=\(config.token)") else { return nil }
|
||||||
|
return url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isLocal: Bool { id.starts(with: "play_local_") }
|
||||||
}
|
}
|
||||||
|
|
||||||
class NowPlayingInfo {
|
class NowPlayingInfo {
|
||||||
|
@ -34,28 +41,17 @@ class NowPlayingInfo {
|
||||||
|
|
||||||
public func setSessionMetadata(metadata: NowPlayingMetadata) {
|
public func setSessionMetadata(metadata: NowPlayingMetadata) {
|
||||||
setMetadata(artwork: nil, metadata: metadata)
|
setMetadata(artwork: nil, metadata: metadata)
|
||||||
|
guard let url = metadata.coverUrl else { return }
|
||||||
let isLocalItem = metadata.itemId.starts(with: "local_")
|
// For local images, "downloading" is occurring off disk, hence this code path works as expected
|
||||||
if isLocalItem {
|
ApiClient.getData(from: url) { [self] image in
|
||||||
guard let artworkUrl = metadata.artworkUrl else { return }
|
guard let downloadedImage = image else {
|
||||||
let coverImage = UIImage(contentsOfFile: artworkUrl)
|
return
|
||||||
guard let coverImage = coverImage else { return }
|
|
||||||
let artwork = MPMediaItemArtwork(boundsSize: coverImage.size) { _ -> UIImage in
|
|
||||||
return coverImage
|
|
||||||
}
|
}
|
||||||
|
let artwork = MPMediaItemArtwork.init(boundsSize: downloadedImage.size, requestHandler: { _ -> UIImage in
|
||||||
|
return downloadedImage
|
||||||
|
})
|
||||||
|
|
||||||
self.setMetadata(artwork: artwork, metadata: metadata)
|
self.setMetadata(artwork: artwork, metadata: metadata)
|
||||||
} else {
|
|
||||||
guard let url = metadata.coverUrl else { return }
|
|
||||||
ApiClient.getData(from: url) { [self] image in
|
|
||||||
guard let downloadedImage = image else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let artwork = MPMediaItemArtwork.init(boundsSize: downloadedImage.size, requestHandler: { _ -> UIImage in
|
|
||||||
return downloadedImage
|
|
||||||
})
|
|
||||||
|
|
||||||
self.setMetadata(artwork: artwork, metadata: metadata)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public func update(duration: Double, currentTime: Double, rate: Float) {
|
public func update(duration: Double, currentTime: Double, rate: Float) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue