Changed pulseaudio with alsaaudio for volume control

This commit is contained in:
Admar Schoonen 2023-04-23 13:24:02 +02:00
parent 7e480e4769
commit 192fbcc687
1 changed files with 21 additions and 17 deletions

View File

@ -67,7 +67,7 @@ from kivy.core.window import Window
if is_arm():
Window.show_cursor = False
import pulsectl
import alsaaudio
import vlc
Builder.load_file('clock.kv')
@ -176,6 +176,15 @@ class MyClockWidget(FloatLayout):
theme_selected = "Dark"
theme = ObjectProperty(Theme(theme_selected))
for x in ('', 'PCM'):
try:
mixer = alsaaudio.Mixer()
break
except:
pass
else:
raise OSError('could not open mixer ' + x)
grabbed = ""
face_numbers = []
@ -966,13 +975,11 @@ class MyClockWidget(FloatLayout):
print("Volume changed to " + str(alarm_settings.volume))
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
# Volume is usually in 0-1.0 range, with >1.0 being soft-boosted
old_vol = pulse.volume_get_all_chans(sink)
pulse.volume_set_all_chans(sink, alarm_settings.volume / 20.0)
new_vol = pulse.volume_get_all_chans(sink)
print("HW volume changed from " + str(old_vol) + " to " + str(new_vol))
# Volume is in 0-100 range
old_vol = self.mixer.getvolume()
self.mixer.setvolume(int(alarm_settings.volume * 5.0))
new_vol = self.mixer.getvolume()
print("HW volume changed from " + str(old_vol) + " to " + str(new_vol))
def wake_up_brightness_slider_value(self, *args):
@ -1294,15 +1301,6 @@ class MyApp(App):
alarm_settings = AlarmSettings()
update_rate = 60.0
# apply volume setting
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
# Volume is usually in 0-1.0 range, with >1.0 being soft-boosted
old_vol = pulse.volume_get_all_chans(sink)
pulse.volume_set_all_chans(sink, alarm_settings.volume / 20.0)
new_vol = pulse.volume_get_all_chans(sink)
print("HW volume changed from " + str(old_vol) + " to " + str(new_vol))
def build(self):
clock_widget = MyClockWidget()
@ -1318,6 +1316,12 @@ class MyApp(App):
if is_arm():
Window.borderless = True
# Volume is in 0-100 range
old_vol = clock_widget.mixer.getvolume()
clock_widget.mixer.setvolume(int(self.alarm_settings.volume * 5.0))
new_vol = clock_widget.mixer.getvolume()
print("HW volume changed from " + str(old_vol) + " to " + str(new_vol))
return clock_widget
def except_hook(type, value, tb):