[英]How can I reproduce a song on loop?
So I need to reproduce my song on loop using VLC.所以我需要使用 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.我相信(只是检查一个旧项目)如果你添加
-1, 0
到media_player.play()
,这样它看起来就像这个media_player.play(-1, 0)
会让它永远循环。 I can't remember exactly what the arguments mean or their requirements but it does make a track loop.我不记得 arguments 的确切含义或他们的要求,但它确实形成了一个轨道循环。
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.它会让您的歌曲继续播放,直到您退出为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.