Home > database >  play as many sounds as loop count in python
play as many sounds as loop count in python

Time:02-13

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 ?

import time
import vlc

alarm = vlc.MediaPlayer("path")
m=0

while m<=10:
   alarm.play()
   time.sleep(1)
   m  =1

CodePudding user response:

just stop the alarm at the end of loop and befor stop it create loop for stop executing while the sound is playing

import time
import vlc

alarm = vlc.MediaPlayer("path")
m = 0

while m <= 10:
    alarm.play()
    time.sleep(1)
    m  = 1
    while alarm.is_playing():
        pass
    alarm.stop()
  • Related