diff --git a/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt b/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt index 9428e7f3..ca23cf45 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/data/DeviceClasses.kt @@ -102,7 +102,8 @@ data class DeviceSettings( var autoSleepTimer: Boolean, var autoSleepTimerStartTime: String, var autoSleepTimerEndTime: String, - var sleepTimerLength: Long // Time in milliseconds + var sleepTimerLength: Long, // Time in milliseconds + var disableSleepTimerFadeOut: Boolean ) { companion object { // Static method to get default device settings @@ -119,7 +120,8 @@ data class DeviceSettings( autoSleepTimer = false, autoSleepTimerStartTime = "22:00", autoSleepTimerEndTime = "06:00", - sleepTimerLength = 900000L // 15 minutes + sleepTimerLength = 900000L, // 15 minutes + disableSleepTimerFadeOut = false ) } } diff --git a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt index f117ca71..a8f8bb11 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt @@ -108,10 +108,16 @@ class SleepTimerManager constructor(private val playerNotificationService: Playe clearSleepTimer() sleepTimerFinishedAt = System.currentTimeMillis() } else if (sleepTimeSecondsRemaining <= 60) { - // Start fading out audio - val volume = sleepTimeSecondsRemaining / 60F - Log.d(tag, "SLEEP VOLUME FADE $volume | ${sleepTimeSecondsRemaining}s remaining") - setVolume(volume) + if (DeviceManager.deviceData.deviceSettings?.disableSleepTimerFadeOut == true) { + // Set volume to 1 in case setting was enabled while fading + setVolume(1f) + } else { + // Start fading out audio down to 10% volume + val percentToReduce = 1 - (sleepTimeSecondsRemaining / 60F) + val volume = 1f - (percentToReduce * 0.9f) + Log.d(tag, "SLEEP VOLUME FADE $volume | ${sleepTimeSecondsRemaining}s remaining") + setVolume(volume) + } } } } diff --git a/pages/settings.vue b/pages/settings.vue index cf559011..d1033a60 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -58,6 +58,13 @@ +
+
+ +
+

Disable audio fade out

+ info +
@@ -109,7 +116,8 @@ export default { autoSleepTimer: false, autoSleepTimerStartTime: '22:00', autoSleepTimerEndTime: '06:00', - sleepTimerLength: 900000 // 15 minutes + sleepTimerLength: 900000, // 15 minutes + disableSleepTimerFadeOut: false }, lockCurrentOrientation: false, settingInfo: { @@ -120,6 +128,10 @@ export default { autoSleepTimer: { name: 'Auto Sleep Timer', message: 'When playing media between the specified start and end times a sleep timer will automatically start.' + }, + disableSleepTimerFadeOut: { + name: 'Disable audio fade out', + message: 'Audio volume will start decreasing when there is less than 1 minute remaining on the sleep timer. Enable this setting to not fade out.' } }, hapticFeedbackItems: [ @@ -263,6 +275,10 @@ export default { this.settings.autoSleepTimer = !this.settings.autoSleepTimer this.saveSettings() }, + toggleDisableSleepTimerFadeOut() { + this.settings.disableSleepTimerFadeOut = !this.settings.disableSleepTimerFadeOut + this.saveSettings() + }, toggleDisableShakeToResetSleepTimer() { this.settings.disableShakeToResetSleepTimer = !this.settings.disableShakeToResetSleepTimer this.saveSettings() @@ -330,6 +346,7 @@ export default { this.settings.autoSleepTimerStartTime = deviceSettings.autoSleepTimerStartTime || '22:00' this.settings.autoSleepTimerEndTime = deviceSettings.autoSleepTimerEndTime || '06:00' this.settings.sleepTimerLength = !isNaN(deviceSettings.sleepTimerLength) ? deviceSettings.sleepTimerLength : 900000 // 15 minutes + this.settings.disableSleepTimerFadeOut = !!deviceSettings.disableSleepTimerFadeOut } }, mounted() {