mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-19 09:08:26 +02:00
fix: iOS chapter sleep timer issues
This commit is contained in:
parent
4e94fd6ad0
commit
5d23c17d30
3 changed files with 18 additions and 18 deletions
|
@ -194,11 +194,6 @@ class AudioPlayer: NSObject {
|
||||||
if self.isSleepTimerSet() {
|
if self.isSleepTimerSet() {
|
||||||
// Update the UI
|
// Update the UI
|
||||||
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
||||||
|
|
||||||
// Handle a sitation where the user skips past the chapter end
|
|
||||||
if self.isChapterSleepTimerBeforeTime(currentTime) {
|
|
||||||
self.removeSleepTimer()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -352,6 +347,9 @@ class AudioPlayer: NSObject {
|
||||||
|
|
||||||
// Update the progress
|
// Update the progress
|
||||||
self.updateNowPlaying()
|
self.updateNowPlaying()
|
||||||
|
|
||||||
|
// Handle a chapter sleep timer that may now be invalid
|
||||||
|
self.handleTrackChangeForChapterSleepTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pause() {
|
public func pause() {
|
||||||
|
|
|
@ -47,9 +47,13 @@ extension AudioPlayer {
|
||||||
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setChapterSleepTimer(stopAt: Double) {
|
public func setChapterSleepTimer(stopAt: Double?) {
|
||||||
logger.log("SLEEP TIMER: Scheduling for chapter end \(stopAt)")
|
|
||||||
self.removeSleepTimer()
|
self.removeSleepTimer()
|
||||||
|
guard let stopAt = stopAt else { return }
|
||||||
|
guard let currentTime = self.getCurrentTime() else { return }
|
||||||
|
guard stopAt >= currentTime else { return }
|
||||||
|
|
||||||
|
logger.log("SLEEP TIMER: Scheduling for chapter end \(stopAt)")
|
||||||
|
|
||||||
// Schedule the observation time
|
// Schedule the observation time
|
||||||
self.sleepTimeChapterStopAt = stopAt
|
self.sleepTimeChapterStopAt = stopAt
|
||||||
|
@ -111,7 +115,12 @@ extension AudioPlayer {
|
||||||
|
|
||||||
// MARK: - Internal helpers
|
// MARK: - Internal helpers
|
||||||
|
|
||||||
internal func decrementSleepTimerIfRunning() {
|
internal func handleTrackChangeForChapterSleepTimer() {
|
||||||
|
// If no sleep timer is set, this does nothing
|
||||||
|
self.setChapterSleepTimer(stopAt: self.sleepTimeChapterStopAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func decrementSleepTimerIfRunning() {
|
||||||
if var sleepTimeRemaining = self.sleepTimeRemaining {
|
if var sleepTimeRemaining = self.sleepTimeRemaining {
|
||||||
sleepTimeRemaining -= 1
|
sleepTimeRemaining -= 1
|
||||||
self.sleepTimeRemaining = sleepTimeRemaining
|
self.sleepTimeRemaining = sleepTimeRemaining
|
||||||
|
@ -137,19 +146,11 @@ extension AudioPlayer {
|
||||||
self.sleepTimeChapterStopAt = nil
|
self.sleepTimeChapterStopAt = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func isChapterSleepTimerBeforeTime(_ time: Double) -> Bool {
|
private func isCountdownSleepTimerSet() -> Bool {
|
||||||
if let chapterStopAt = self.sleepTimeChapterStopAt {
|
|
||||||
return chapterStopAt <= time
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
internal func isCountdownSleepTimerSet() -> Bool {
|
|
||||||
return self.sleepTimeRemaining != nil
|
return self.sleepTimeRemaining != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func isChapterSleepTimerSet() -> Bool {
|
private func isChapterSleepTimerSet() -> Bool {
|
||||||
return self.sleepTimeChapterStopAt != nil
|
return self.sleepTimeChapterStopAt != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,6 +244,7 @@ class Database {
|
||||||
public func getPlaybackSession(id: String) -> PlaybackSession? {
|
public func getPlaybackSession(id: String) -> PlaybackSession? {
|
||||||
do {
|
do {
|
||||||
let realm = try Realm()
|
let realm = try Realm()
|
||||||
|
realm.refresh() // Refresh, because working with stale sessions leads to wrong times
|
||||||
return realm.object(ofType: PlaybackSession.self, forPrimaryKey: id)
|
return realm.object(ofType: PlaybackSession.self, forPrimaryKey: id)
|
||||||
} catch {
|
} catch {
|
||||||
debugPrint(error)
|
debugPrint(error)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue