mirror of
https://github.com/sudoxnym/audiobookshelf-atv.git
synced 2026-04-14 19:46:30 +00:00
Update:Android sleep timer resets on play #260
This commit is contained in:
parent
f8a6b6a936
commit
03240415b8
2 changed files with 9 additions and 5 deletions
|
|
@ -20,7 +20,6 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||
private var sleepTimerEndTime:Long = 0L
|
||||
private var sleepTimerLength:Long = 0L
|
||||
private var sleepTimerElapsed:Long = 0L
|
||||
private var sleepTimerExtensionTime:Long = 0L
|
||||
private var sleepTimerFinishedAt:Long = 0L
|
||||
|
||||
private fun getCurrentTime():Long {
|
||||
|
|
@ -74,7 +73,6 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||
}
|
||||
sleepTimerEndTime = time
|
||||
sleepTimerLength = 0
|
||||
sleepTimerExtensionTime = SLEEP_EXTENSION_TIME
|
||||
|
||||
if (sleepTimerEndTime > getDuration()) {
|
||||
sleepTimerEndTime = getDuration()
|
||||
|
|
@ -82,7 +80,6 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||
} else {
|
||||
sleepTimerLength = time
|
||||
sleepTimerEndTime = 0L
|
||||
sleepTimerExtensionTime = time
|
||||
|
||||
if (sleepTimerLength + getCurrentTime() > getDuration()) {
|
||||
sleepTimerLength = getDuration() - getCurrentTime()
|
||||
|
|
@ -123,6 +120,12 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||
return true
|
||||
}
|
||||
|
||||
// Called when playing audio and only applies to regular timer
|
||||
fun resetSleepTimer() {
|
||||
if (!sleepTimerRunning || sleepTimerLength <= 0L) return
|
||||
setSleepTimer(sleepTimerLength, false)
|
||||
}
|
||||
|
||||
private fun clearSleepTimer() {
|
||||
sleepTimerTask?.cancel()
|
||||
sleepTimerTask = null
|
||||
|
|
@ -177,7 +180,7 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||
return
|
||||
}
|
||||
|
||||
val newSleepTime = if (sleepTimerExtensionTime >= 0) sleepTimerExtensionTime else SLEEP_EXTENSION_TIME
|
||||
val newSleepTime = if (sleepTimerLength >= 0) sleepTimerLength else SLEEP_EXTENSION_TIME
|
||||
vibrate()
|
||||
setSleepTimer(newSleepTime, false)
|
||||
play()
|
||||
|
|
@ -187,7 +190,7 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||
// Does not apply to chapter sleep timers and timer must be running for at least 3 seconds
|
||||
if (sleepTimerEndTime == 0L && sleepTimerElapsed > 3000L) {
|
||||
vibrate()
|
||||
setSleepTimer(sleepTimerExtensionTime, false)
|
||||
setSleepTimer(sleepTimerLength, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ class PlayerListener(var playerNotificationService:PlayerNotificationService) :
|
|||
|
||||
// Start/stop progress sync interval
|
||||
if (isPlaying) {
|
||||
playerNotificationService.sleepTimerManager.resetSleepTimer() // Reset sleep timer if running and not a chapter timer
|
||||
player.volume = 1F // Volume on sleep timer might have decreased this
|
||||
val playbackSession: PlaybackSession? = playerNotificationService.mediaProgressSyncer.currentPlaybackSession ?: playerNotificationService.currentPlaybackSession
|
||||
playbackSession?.let { playerNotificationService.mediaProgressSyncer.play(it) }
|
||||
|
|
|
|||
Loading…
Reference in a new issue