简体   繁体   English

无法使用 pygame.mixer.music 在歌曲之间循环

[英]Not able to loop between songs using pygame.mixer.music

def selection():
    for song in my_music:
        print(song)
        pygame.mixer.music.load(song)
        pygame.mixer.music.play(loops=0)

Here my_music is list containing the paths of mp3 files that i want to play but, the problem is that it plays only first file though the my_music list contains more than 5. I also used print(song) to check but it prints the paths of all files but plays only one.这里my_music是包含我想要播放的 mp3 文件路径的列表,但问题是它只播放第一个文件,尽管my_music列表包含超过 5 个。我还使用print(song)进行检查,但它打印了路径所有文件,但只播放一个。 can someone help!!有人可以帮忙!!

the pygame.mixer.music.play() is not blocking. pygame.mixer.music.play()没有阻塞。 The songs need to be queued into the mixer and then played.歌曲需要排队进入混音器然后播放。 The loops=x argument is used to repeat the songs in the queue loops=x参数用于重复队列中的歌曲

def play_songs(song_list):
    for song in song_list:
        print("queueing song: {}".format(song))
        pygame.mixer.music.queue(song)
    print("now playing...")
    pygame.mixer.music.play(loops=-1)        # -1 means repeat forever

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM