mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +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() {
|
||||
// Update the UI
|
||||
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
|
||||
self.updateNowPlaying()
|
||||
|
||||
// Handle a chapter sleep timer that may now be invalid
|
||||
self.handleTrackChangeForChapterSleepTimer()
|
||||
}
|
||||
|
||||
public func pause() {
|
||||
|
|
|
@ -47,9 +47,13 @@ extension AudioPlayer {
|
|||
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
||||
}
|
||||
|
||||
public func setChapterSleepTimer(stopAt: Double) {
|
||||
logger.log("SLEEP TIMER: Scheduling for chapter end \(stopAt)")
|
||||
public func setChapterSleepTimer(stopAt: Double?) {
|
||||
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
|
||||
self.sleepTimeChapterStopAt = stopAt
|
||||
|
@ -111,7 +115,12 @@ extension AudioPlayer {
|
|||
|
||||
// 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 {
|
||||
sleepTimeRemaining -= 1
|
||||
self.sleepTimeRemaining = sleepTimeRemaining
|
||||
|
@ -137,19 +146,11 @@ extension AudioPlayer {
|
|||
self.sleepTimeChapterStopAt = nil
|
||||
}
|
||||
|
||||
internal func isChapterSleepTimerBeforeTime(_ time: Double) -> Bool {
|
||||
if let chapterStopAt = self.sleepTimeChapterStopAt {
|
||||
return chapterStopAt <= time
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
internal func isCountdownSleepTimerSet() -> Bool {
|
||||
private func isCountdownSleepTimerSet() -> Bool {
|
||||
return self.sleepTimeRemaining != nil
|
||||
}
|
||||
|
||||
internal func isChapterSleepTimerSet() -> Bool {
|
||||
private func isChapterSleepTimerSet() -> Bool {
|
||||
return self.sleepTimeChapterStopAt != nil
|
||||
}
|
||||
|
||||
|
|
|
@ -244,6 +244,7 @@ class Database {
|
|||
public func getPlaybackSession(id: String) -> PlaybackSession? {
|
||||
do {
|
||||
let realm = try Realm()
|
||||
realm.refresh() // Refresh, because working with stale sessions leads to wrong times
|
||||
return realm.object(ofType: PlaybackSession.self, forPrimaryKey: id)
|
||||
} catch {
|
||||
debugPrint(error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue