如何循环播放歌曲?

How can I reproduce a song on loop?

所以我需要使用 VLC 循环播放我的歌曲。我使用了这段代码,当我播放它时,它只播放一次歌曲然后程序停止。我该如何解决?这是代码:

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)

我相信(只是检查一个旧项目),如果您将 -1, 0 添加到 media_player.play() 以便它看起来像这样 media_player.play(-1, 0) 将使它永远循环。我不记得这些参数的确切含义或它们的要求,但它确实构成了一个轨道循环。

希望我做对了,这对你有帮助:)

试试这个代码。

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

它会让您的歌曲继续播放直到您退出。