mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-21 10:08:21 +02:00
Fix: scale end of chapter time by playback speed
This commit is contained in:
parent
16472e1de8
commit
161614f6c9
1 changed files with 27 additions and 8 deletions
|
@ -49,6 +49,14 @@ constructor(private val playerNotificationService: PlayerNotificationService) {
|
||||||
return playerNotificationService.currentPlayer.isPlaying
|
return playerNotificationService.currentPlayer.isPlaying
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the playback speed of the player.
|
||||||
|
* @return Float - the playback speed.
|
||||||
|
*/
|
||||||
|
private fun getPlaybackSpeed(): Float {
|
||||||
|
return playerNotificationService.currentPlayer.playbackParameters.speed
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the volume of the player.
|
* Sets the volume of the player.
|
||||||
* @param volume Float - the volume level to set.
|
* @param volume Float - the volume level to set.
|
||||||
|
@ -69,15 +77,16 @@ constructor(private val playerNotificationService: PlayerNotificationService) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the remaining time of the sleep timer in seconds.
|
* Gets the remaining time of the sleep timer in seconds.
|
||||||
|
* @param speed Float - the playback speed of the player, default value is 1.
|
||||||
* @return Int - the remaining time in seconds.
|
* @return Int - the remaining time in seconds.
|
||||||
*/
|
*/
|
||||||
private fun getSleepTimerTimeRemainingSeconds(): Int {
|
private fun getSleepTimerTimeRemainingSeconds(speed: Float = 1f): Int {
|
||||||
if (sleepTimerEndTime == 0L && sleepTimerLength > 0) { // For regular timer
|
if (sleepTimerEndTime == 0L && sleepTimerLength > 0) { // For regular timer
|
||||||
return ((sleepTimerLength - sleepTimerElapsed) / 1000).toDouble().roundToInt()
|
return ((sleepTimerLength - sleepTimerElapsed) / 1000).toDouble().roundToInt()
|
||||||
}
|
}
|
||||||
// For chapter end timer
|
// For chapter end timer
|
||||||
if (sleepTimerEndTime <= 0) return 0
|
if (sleepTimerEndTime <= 0) return 0
|
||||||
return (((sleepTimerEndTime - getCurrentTime()) / 1000).toDouble()).roundToInt()
|
return (((sleepTimerEndTime - getCurrentTime()) / 1000).toDouble() / speed).roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +124,7 @@ constructor(private val playerNotificationService: PlayerNotificationService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
playerNotificationService.clientEventEmitter?.onSleepTimerSet(
|
playerNotificationService.clientEventEmitter?.onSleepTimerSet(
|
||||||
getSleepTimerTimeRemainingSeconds(),
|
getSleepTimerTimeRemainingSeconds(getPlaybackSpeed()),
|
||||||
isAutoSleepTimer
|
isAutoSleepTimer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -125,7 +134,8 @@ constructor(private val playerNotificationService: PlayerNotificationService) {
|
||||||
if (getIsPlaying()) {
|
if (getIsPlaying()) {
|
||||||
sleepTimerElapsed += 1000L
|
sleepTimerElapsed += 1000L
|
||||||
|
|
||||||
val sleepTimeSecondsRemaining = getSleepTimerTimeRemainingSeconds()
|
val sleepTimeSecondsRemaining =
|
||||||
|
getSleepTimerTimeRemainingSeconds(getPlaybackSpeed())
|
||||||
Log.d(
|
Log.d(
|
||||||
tag,
|
tag,
|
||||||
"Timer Elapsed $sleepTimerElapsed | Sleep TIMER time remaining $sleepTimeSecondsRemaining s"
|
"Timer Elapsed $sleepTimerElapsed | Sleep TIMER time remaining $sleepTimeSecondsRemaining s"
|
||||||
|
@ -364,15 +374,18 @@ constructor(private val playerNotificationService: PlayerNotificationService) {
|
||||||
// Increase the sleep timer time (if using fixed length) or end time (if using chapter end time)
|
// Increase the sleep timer time (if using fixed length) or end time (if using chapter end time)
|
||||||
// and ensure it doesn't go over the duration of the current playback item
|
// and ensure it doesn't go over the duration of the current playback item
|
||||||
if (sleepTimerEndTime == 0L) {
|
if (sleepTimerEndTime == 0L) {
|
||||||
|
// Fixed length
|
||||||
sleepTimerLength += time
|
sleepTimerLength += time
|
||||||
sleepTimerLength = minOf(sleepTimerLength, getDuration() - getCurrentTime())
|
sleepTimerLength = minOf(sleepTimerLength, getDuration() - getCurrentTime())
|
||||||
} else {
|
} else {
|
||||||
sleepTimerEndTime = minOf(sleepTimerEndTime + time, getDuration())
|
// Chapter end time
|
||||||
|
sleepTimerEndTime =
|
||||||
|
minOf(sleepTimerEndTime + (time * getPlaybackSpeed()).roundToInt(), getDuration())
|
||||||
}
|
}
|
||||||
|
|
||||||
setVolume(1F)
|
setVolume(1F)
|
||||||
playerNotificationService.clientEventEmitter?.onSleepTimerSet(
|
playerNotificationService.clientEventEmitter?.onSleepTimerSet(
|
||||||
getSleepTimerTimeRemainingSeconds(),
|
getSleepTimerTimeRemainingSeconds(getPlaybackSpeed()),
|
||||||
isAutoSleepTimer
|
isAutoSleepTimer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -388,14 +401,20 @@ constructor(private val playerNotificationService: PlayerNotificationService) {
|
||||||
// Decrease the sleep timer time (if using fixed length) or end time (if using chapter end time)
|
// Decrease the sleep timer time (if using fixed length) or end time (if using chapter end time)
|
||||||
// and ensure it doesn't go below 1 second
|
// and ensure it doesn't go below 1 second
|
||||||
if (sleepTimerEndTime == 0L) {
|
if (sleepTimerEndTime == 0L) {
|
||||||
|
// Fixed length
|
||||||
sleepTimerLength = maxOf(sleepTimerLength - time, 1000L)
|
sleepTimerLength = maxOf(sleepTimerLength - time, 1000L)
|
||||||
} else {
|
} else {
|
||||||
sleepTimerEndTime = maxOf(sleepTimerEndTime - time, getCurrentTime() + 1000)
|
// Chapter end time
|
||||||
|
sleepTimerEndTime =
|
||||||
|
maxOf(
|
||||||
|
sleepTimerEndTime - (time * getPlaybackSpeed()).roundToInt(),
|
||||||
|
getCurrentTime() + 1000
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
setVolume(1F)
|
setVolume(1F)
|
||||||
playerNotificationService.clientEventEmitter?.onSleepTimerSet(
|
playerNotificationService.clientEventEmitter?.onSleepTimerSet(
|
||||||
getSleepTimerTimeRemainingSeconds(),
|
getSleepTimerTimeRemainingSeconds(getPlaybackSpeed()),
|
||||||
isAutoSleepTimer
|
isAutoSleepTimer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue