I want the alarm.play() function to repeat for the number of loops and ring 10 times as in the example, but it just keeps ringing once every time I try or change it. How can I fix this? And does it make more sense to use for instead of while ?
JavaScript
x
12
12
1
import time
2
import vlc
3
4
alarm = vlc.MediaPlayer("path")
5
m=0
6
7
while m<=10:
8
alarm.play()
9
time.sleep(1)
10
m +=1
11
12
Advertisement
Answer
just stop
the alarm at the end of loop and befor stop it create loop for stop executing while the sound is playing
JavaScript
1
14
14
1
import time
2
import vlc
3
4
alarm = vlc.MediaPlayer("path")
5
m = 0
6
7
while m <= 10:
8
alarm.play()
9
time.sleep(1)
10
m += 1
11
while alarm.is_playing():
12
pass
13
alarm.stop()
14