mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-21 19:25:00 +02:00
Functions to update local progress
This commit is contained in:
parent
c32c77b963
commit
f4e39ec7ca
4 changed files with 39 additions and 0 deletions
|
@ -151,6 +151,8 @@ struct LocalMediaProgress: Realmable, Codable {
|
|||
var libraryItemId: String?
|
||||
var episodeId: String?
|
||||
|
||||
var progressPercent: Int { Int(self.progress * 100) }
|
||||
|
||||
static func primaryKey() -> String? {
|
||||
return "id"
|
||||
}
|
||||
|
|
|
@ -152,4 +152,32 @@ extension LocalMediaProgress {
|
|||
self.startedAt = progress.startedAt
|
||||
self.finishedAt = progress.finishedAt
|
||||
}
|
||||
|
||||
mutating func updateIsFinished(_ finished: Bool) {
|
||||
if self.isFinished != finished {
|
||||
self.progress = finished ? 1.0 : 0.0
|
||||
}
|
||||
|
||||
self.isFinished = finished
|
||||
self.lastUpdate = Int(Date().timeIntervalSince1970)
|
||||
self.finishedAt = finished ? lastUpdate : nil
|
||||
}
|
||||
|
||||
mutating func updateFromPlaybackSession(_ playbackSession: PlaybackSession) {
|
||||
self.currentTime = playbackSession.currentTime
|
||||
self.progress = playbackSession.progress
|
||||
self.lastUpdate = Int(Date().timeIntervalSince1970)
|
||||
self.isFinished = playbackSession.progress >= 100.0
|
||||
self.finishedAt = self.isFinished ? self.lastUpdate : nil
|
||||
}
|
||||
|
||||
mutating func updateFromServerMediaProgress(_ serverMediaProgress: MediaProgress) {
|
||||
self.isFinished = serverMediaProgress.isFinished
|
||||
self.progress = serverMediaProgress.progress
|
||||
self.currentTime = serverMediaProgress.currentTime
|
||||
self.duration = serverMediaProgress.duration
|
||||
self.lastUpdate = serverMediaProgress.lastUpdate
|
||||
self.finishedAt = serverMediaProgress.finishedAt
|
||||
self.startedAt = serverMediaProgress.startedAt
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,4 +29,11 @@ struct PlaybackSession: Decodable, Encodable {
|
|||
var localLibraryItem: LocalLibraryItem?
|
||||
var serverConnectionConfigId: String?
|
||||
var serverAddress: String?
|
||||
|
||||
var totalDuration: Double {
|
||||
var total = 0.0
|
||||
self.audioTracks.forEach { total += $0.duration }
|
||||
return total
|
||||
}
|
||||
var progress: Double { self.currentTime / self.totalDuration }
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ class NowPlayingInfo {
|
|||
|
||||
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
nowPlayingInfo = [:]
|
||||
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
|
||||
|
@ -89,6 +90,7 @@ class NowPlayingInfo {
|
|||
nowPlayingInfo[MPMediaItemPropertyArtist] = metadata!.author ?? "unknown"
|
||||
nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = metadata!.series
|
||||
}
|
||||
|
||||
private func shouldFetchCover(id: String) -> Bool {
|
||||
nowPlayingInfo[MPNowPlayingInfoPropertyExternalContentIdentifier] as? String != id || nowPlayingInfo[MPMediaItemPropertyArtwork] == nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue