Immediately change volume when playing audio

This commit is contained in:
Admar Schoonen 2023-04-23 16:32:05 +02:00
parent d3d3d4d040
commit 261230f999
1 changed files with 11 additions and 7 deletions

View File

@ -134,7 +134,7 @@ class AlarmSettings():
seconds_to_sunrise = 30 * 60 # 30 minutes
volume = 15
wake_up_volume = 15
wake_up_brightness = 20
reading_light_brightness = 1
display_brightness = 10
@ -398,7 +398,7 @@ class MyClockWidget(FloatLayout):
(self.player.get_state() == vlc.State.Ended) or \
(self.player.get_state() == vlc.State.Error):
print("beep beep! " + source)
self.volume_target = alarm_settings.volume / 20.0
self.volume_target = alarm_settings.wake_up_volume / 20.0
media = self.vlc.media_new(source)
self.player.set_media(media)
self.player.play()
@ -1010,13 +1010,17 @@ class MyClockWidget(FloatLayout):
def volume_slider_value(self, *args):
alarm_settings = App.get_running_app().alarm_settings
alarm_settings.volume = int(args[1])
alarm_settings.wake_up_volume = int(args[1])
print("Volume changed to " + str(alarm_settings.volume))
print("Volume changed to " + str(alarm_settings.wake_up_volume))
old_vol = self.mixer.getvolume()
self.volume_target = alarm_settings.volume / 20.0
self.set_volume(self.volume_target)
if (alarm_settings.alarm_playing) and (self.player.get_state() == vlc.State.Playing):
# immediately set volume when audio is playing
self.volume_target = alarm_settings.wake_up_volume / 20.0
self.set_volume(self.volume_target)
new_vol = self.mixer.getvolume()
print("HW volume changed from " + str(old_vol) + " to " + str(new_vol))
@ -1357,7 +1361,7 @@ class MyApp(App):
# Volume is in 0-1.0 range
old_vol = clock_widget.mixer.getvolume()
clock_widget.volume_target = self.alarm_settings.volume / 20.0
clock_widget.volume_target = self.alarm_settings.wake_up_volume / 20.0
new_vol = clock_widget.mixer.getvolume()
print("HW volume changed from " + str(old_vol) + " to " + str(new_vol))