mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-09-01 16:17:25 +02:00
Update:Android sleep timer resets on play #260
This commit is contained in:
@@ -20,7 +20,6 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||||||
private var sleepTimerEndTime:Long = 0L
|
private var sleepTimerEndTime:Long = 0L
|
||||||
private var sleepTimerLength:Long = 0L
|
private var sleepTimerLength:Long = 0L
|
||||||
private var sleepTimerElapsed:Long = 0L
|
private var sleepTimerElapsed:Long = 0L
|
||||||
private var sleepTimerExtensionTime:Long = 0L
|
|
||||||
private var sleepTimerFinishedAt:Long = 0L
|
private var sleepTimerFinishedAt:Long = 0L
|
||||||
|
|
||||||
private fun getCurrentTime():Long {
|
private fun getCurrentTime():Long {
|
||||||
@@ -74,7 +73,6 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||||||
}
|
}
|
||||||
sleepTimerEndTime = time
|
sleepTimerEndTime = time
|
||||||
sleepTimerLength = 0
|
sleepTimerLength = 0
|
||||||
sleepTimerExtensionTime = SLEEP_EXTENSION_TIME
|
|
||||||
|
|
||||||
if (sleepTimerEndTime > getDuration()) {
|
if (sleepTimerEndTime > getDuration()) {
|
||||||
sleepTimerEndTime = getDuration()
|
sleepTimerEndTime = getDuration()
|
||||||
@@ -82,7 +80,6 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||||||
} else {
|
} else {
|
||||||
sleepTimerLength = time
|
sleepTimerLength = time
|
||||||
sleepTimerEndTime = 0L
|
sleepTimerEndTime = 0L
|
||||||
sleepTimerExtensionTime = time
|
|
||||||
|
|
||||||
if (sleepTimerLength + getCurrentTime() > getDuration()) {
|
if (sleepTimerLength + getCurrentTime() > getDuration()) {
|
||||||
sleepTimerLength = getDuration() - getCurrentTime()
|
sleepTimerLength = getDuration() - getCurrentTime()
|
||||||
@@ -123,6 +120,12 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||||||
return true
|
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() {
|
private fun clearSleepTimer() {
|
||||||
sleepTimerTask?.cancel()
|
sleepTimerTask?.cancel()
|
||||||
sleepTimerTask = null
|
sleepTimerTask = null
|
||||||
@@ -177,7 +180,7 @@ class SleepTimerManager constructor(val playerNotificationService: PlayerNotific
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val newSleepTime = if (sleepTimerExtensionTime >= 0) sleepTimerExtensionTime else SLEEP_EXTENSION_TIME
|
val newSleepTime = if (sleepTimerLength >= 0) sleepTimerLength else SLEEP_EXTENSION_TIME
|
||||||
vibrate()
|
vibrate()
|
||||||
setSleepTimer(newSleepTime, false)
|
setSleepTimer(newSleepTime, false)
|
||||||
play()
|
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
|
// Does not apply to chapter sleep timers and timer must be running for at least 3 seconds
|
||||||
if (sleepTimerEndTime == 0L && sleepTimerElapsed > 3000L) {
|
if (sleepTimerEndTime == 0L && sleepTimerElapsed > 3000L) {
|
||||||
vibrate()
|
vibrate()
|
||||||
setSleepTimer(sleepTimerExtensionTime, false)
|
setSleepTimer(sleepTimerLength, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ class PlayerListener(var playerNotificationService:PlayerNotificationService) :
|
|||||||
|
|
||||||
// Start/stop progress sync interval
|
// Start/stop progress sync interval
|
||||||
if (isPlaying) {
|
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
|
player.volume = 1F // Volume on sleep timer might have decreased this
|
||||||
val playbackSession: PlaybackSession? = playerNotificationService.mediaProgressSyncer.currentPlaybackSession ?: playerNotificationService.currentPlaybackSession
|
val playbackSession: PlaybackSession? = playerNotificationService.mediaProgressSyncer.currentPlaybackSession ?: playerNotificationService.currentPlaybackSession
|
||||||
playbackSession?.let { playerNotificationService.mediaProgressSyncer.play(it) }
|
playbackSession?.let { playerNotificationService.mediaProgressSyncer.play(it) }
|
||||||
|
|||||||
Reference in New Issue
Block a user