So I need to reproduce my song on loop using VLC. I used this code and when I play it, it only plays the song once and then the program stops. How can I fix it? Here is the code:
def reproduce_song():
player = vlc.Instance()
media_list = player.media_list_new()
media_player = player.media_list_player_new()
media = player.media_new("Complements//song1.mp3")
media_list.add_media(media)
media_player.set_media_list(media_list)
player.vlm_set_loop("Complements//song1.mp3", True)
media_player.play()
time.sleep(120)
I believe (just checking an old project) that if you add -1, 0
to media_player.play()
so that it looks like this media_player.play(-1, 0)
will make it loop forever. I can't remember exactly what the arguments mean or their requirements but it does make a track loop.
Hope I got this right, and it helps:)
Try this code.
def reproduce_song():
player = vlc.Instance()
media_list = player.media_list_new()
media_player = player.media_list_player_new()
media = player.media_new("Complements//song1.mp3")
media_list.add_media(media)
media_player.set_media_list(media_list)
player.vlm_set_loop("Complements//song1.mp3", True)
media_player.play()
time.sleep(120)
flag = True
while flag:
reproduce_song()
quit_input = input()
if quit_input == "q": # To quit your program manually.
flag = False
It will make your song continue playing until you quit it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.