Adding repeat alarm

Note: does not work when HTTP stream fails since playsound blocks when stream fails
This commit is contained in:
Admar Schoonen 2022-12-17 18:07:39 +01:00
parent 2b82941f9c
commit be158d1bed
1 changed files with 12 additions and 5 deletions

View File

@ -50,10 +50,17 @@ Position = collections.namedtuple('Position', 'x y')
global sound_process
sound_process = None
def play_sound(source):
def play_sound(sound_source, backup_sound_source):
failures = 0
source = sound_source
while True:
print("beep beep!")
print("beep beep! " + source)
playsound(source)
if source.startswith(("http://", "https://")) and failures < 3:
failures += 1
if failures >= 3:
source = backup_sound_source
class MyClockWidget(FloatLayout):
set_alarm_mode = False
@ -66,8 +73,8 @@ class MyClockWidget(FloatLayout):
alarm_modified = False
seconds_to_next_alarm = False
led_color = [0, 0, 0]
# sound_source = "https://icecast.omroep.nl/radio1-bb-mp3"
sound_source = "Woodpecker Chirps - QuickSounds.com.mp3"
sound_source = "https://icecast.omroep.nl/radio1-bb-mp3"
backup_sound_source = "Woodpecker Chirps - QuickSounds.com.mp3"
def draw_face(self):
"""
@ -167,7 +174,7 @@ class MyClockWidget(FloatLayout):
return
if self.seconds_to_next_alarm < 0.1 and sound_process is None:
sound_process = Process(target=play_sound, args=(self.sound_source,))
sound_process = Process(target=play_sound, args=(self.sound_source, self.backup_sound_source,))
sound_process.start()
def calc_seconds_to_next_alarm(self):