0

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

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.