mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-29 23:25:47 +02:00
Fixed metatdata
This commit is contained in:
parent
736af85855
commit
6c65c8a33e
9 changed files with 51 additions and 16 deletions
|
@ -9,6 +9,7 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
2FAD9763203C412B000D30F8 /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2FAD9762203C412B000D30F8 /* config.xml */; };
|
||||
3A200C1527D64D7E00CBF02E /* AudioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A200C1427D64D7E00CBF02E /* AudioPlayer.swift */; };
|
||||
3AB34053280829BF0039308B /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB34052280829BF0039308B /* Extensions.swift */; };
|
||||
3ABF580928059BAE005DFBE5 /* PlaybackSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABF580828059BAE005DFBE5 /* PlaybackSession.swift */; };
|
||||
3ABF580B2805A837005DFBE5 /* PlaybackReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABF580A2805A837005DFBE5 /* PlaybackReport.swift */; };
|
||||
3ABF618F2804325C0070250E /* PlayerHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABF618E2804325C0070250E /* PlayerHandler.swift */; };
|
||||
|
@ -33,6 +34,7 @@
|
|||
/* Begin PBXFileReference section */
|
||||
2FAD9762203C412B000D30F8 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = config.xml; sourceTree = "<group>"; };
|
||||
3A200C1427D64D7E00CBF02E /* AudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = "<group>"; };
|
||||
3AB34052280829BF0039308B /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
|
||||
3ABF580828059BAE005DFBE5 /* PlaybackSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackSession.swift; sourceTree = "<group>"; };
|
||||
3ABF580A2805A837005DFBE5 /* PlaybackReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackReport.swift; sourceTree = "<group>"; };
|
||||
3ABF618E2804325C0070250E /* PlayerHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerHandler.swift; sourceTree = "<group>"; };
|
||||
|
@ -126,6 +128,7 @@
|
|||
3AD4FCEA280443DD006DB301 /* Database.swift */,
|
||||
3AD4FCEC28044E6C006DB301 /* Store.swift */,
|
||||
3AF1970B2806E2590096F747 /* ApiClient.swift */,
|
||||
3AB34052280829BF0039308B /* Extensions.swift */,
|
||||
);
|
||||
path = util;
|
||||
sourceTree = "<group>";
|
||||
|
@ -298,6 +301,7 @@
|
|||
3AD4FCE928043FD7006DB301 /* ServerConnectionConfig.swift in Sources */,
|
||||
3A200C1527D64D7E00CBF02E /* AudioPlayer.swift in Sources */,
|
||||
3AFCB5E827EA240D00ECCC05 /* NowPlayingInfo.swift in Sources */,
|
||||
3AB34053280829BF0039308B /* Extensions.swift in Sources */,
|
||||
3AD4FCEB280443DD006DB301 /* Database.swift in Sources */,
|
||||
3AD4FCE528043E50006DB301 /* AbsDatabase.swift in Sources */,
|
||||
3AF197102806E3DC0096F747 /* AbsAudioPlayer.m in Sources */,
|
||||
|
|
|
@ -25,8 +25,15 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
}
|
||||
|
||||
ApiClient.startPlaybackSession(libraryItemId: libraryItemId!, episodeId: episodeId) { session in
|
||||
NSLog(OperationQueue.current)
|
||||
PlayerHandler.startPlayback(session: session, playWhenReady: playWhenReady)
|
||||
do {
|
||||
call.resolve(try session.asDictionary())
|
||||
} catch(let exception) {
|
||||
NSLog("failed to convert session to json")
|
||||
debugPrint(exception)
|
||||
|
||||
call.resolve([:])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
struct PlaybackSession: Decodable {
|
||||
struct PlaybackSession: Decodable, Encodable {
|
||||
var id: String
|
||||
var userId: String?
|
||||
var libraryItemId: String?
|
||||
|
@ -30,13 +30,13 @@ struct PlaybackSession: Decodable {
|
|||
var serverConnectionConfigId: String?
|
||||
var serverAddress: String?
|
||||
}
|
||||
struct Chapter: Decodable {
|
||||
struct Chapter: Decodable, Encodable {
|
||||
var id: Int
|
||||
var start: Double
|
||||
var end: Double
|
||||
var title: String?
|
||||
}
|
||||
struct AudioTrack: Decodable {
|
||||
struct AudioTrack: Decodable, Encodable {
|
||||
var index: Int?
|
||||
var startOffset: Double
|
||||
var duration: Double
|
||||
|
@ -49,7 +49,7 @@ struct AudioTrack: Decodable {
|
|||
// var audioProbeResult: AudioProbeResult? Needed for local playback
|
||||
var serverIndex: Int?
|
||||
}
|
||||
struct FileMetadata: Decodable {
|
||||
struct FileMetadata: Decodable, Encodable {
|
||||
var filename: String
|
||||
var ext: String
|
||||
var path: String
|
||||
|
|
|
@ -75,9 +75,9 @@ class AudioPlayer: NSObject {
|
|||
print(error)
|
||||
}
|
||||
|
||||
DispatchQueue.main.sync {
|
||||
// DispatchQueue.main.sync {
|
||||
UIApplication.shared.endReceivingRemoteControlEvents()
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
// MARK: - Methods
|
||||
|
@ -165,7 +165,8 @@ class AudioPlayer: NSObject {
|
|||
"Authorization": "Bearer \(Store.serverConfig.token)"
|
||||
]
|
||||
|
||||
return AVURLAsset(url: URL(string: activeAudioTrack.contentUrl)!, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
|
||||
debugPrint(activeAudioTrack)
|
||||
return AVURLAsset(url: URL(string: "\(Store.serverConfig.address)\(activeAudioTrack.contentUrl)")!, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
|
||||
}
|
||||
private func initAudioSession() {
|
||||
do {
|
||||
|
@ -179,9 +180,9 @@ class AudioPlayer: NSObject {
|
|||
|
||||
// MARK: - Now playing
|
||||
private func setupRemoteTransportControls() {
|
||||
DispatchQueue.main.sync {
|
||||
// DispatchQueue.main.sync {
|
||||
UIApplication.shared.beginReceivingRemoteControlEvents()
|
||||
}
|
||||
// }
|
||||
let commandCenter = MPRemoteCommandCenter.shared()
|
||||
|
||||
commandCenter.playCommand.isEnabled = true
|
||||
|
|
|
@ -17,7 +17,7 @@ class PlayerHandler {
|
|||
player = nil
|
||||
}
|
||||
|
||||
NowPlayingInfo.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, artworkUrl: "\(Store.serverConfig.address)/api/items/\(String(describing: session.libraryItemId))/cover?token=\(Store.serverConfig.token)", title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil))
|
||||
NowPlayingInfo.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, artworkUrl: session.coverPath, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil))
|
||||
self.session = session
|
||||
player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
extension String: Error {}
|
||||
|
||||
class Database {
|
||||
public static let realmQueue = DispatchQueue(label: "realm-queue")
|
||||
|
||||
|
|
20
ios/App/Shared/util/Extensions.swift
Normal file
20
ios/App/Shared/util/Extensions.swift
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// Extensions.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 14.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String: Error {}
|
||||
|
||||
extension Encodable {
|
||||
func asDictionary() throws -> [String: Any] {
|
||||
let data = try JSONEncoder().encode(self)
|
||||
guard let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
|
||||
throw NSError()
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ func getData(from url: URL, completion: @escaping (UIImage?) -> Void) {
|
|||
|
||||
struct NowPlayingMetadata {
|
||||
var id: String
|
||||
var itemId: String
|
||||
var artworkUrl: String?
|
||||
var title: String
|
||||
var author: String?
|
||||
|
@ -28,13 +29,18 @@ class NowPlayingInfo {
|
|||
private static var nowPlayingInfo: [String: Any] = [:]
|
||||
|
||||
public static func setSessionMetadata(metadata: NowPlayingMetadata) {
|
||||
setMetadata(artwork: nil, metadata: nil)
|
||||
setMetadata(artwork: nil, metadata: metadata)
|
||||
|
||||
/*
|
||||
if !shouldFetchCover(id: metadata.id) || metadata.artworkUrl == nil {
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
guard let url = URL(string: "\(Store.serverConfig.address)/api/items/\(metadata.itemId)/cover?token=\(Store.serverConfig.token)") else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let url = URL(string: metadata.artworkUrl!) else { return }
|
||||
getData(from: url) { [self] image in
|
||||
guard let downloadedImage = image else {
|
||||
return
|
||||
|
|
|
@ -10,7 +10,6 @@ import RealmSwift
|
|||
|
||||
class Store {
|
||||
@ThreadSafe private static var _serverConfig: ServerConnectionConfig?
|
||||
// ONLY USE REALM IN Database.realmQueue OR ELSE THE APP WILL CRASH
|
||||
public static var serverConfig: ServerConnectionConfig {
|
||||
get {
|
||||
if _serverConfig == nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue