+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Not able to loop between songs using pygame.mixer.music

发布于2021-03-06 18:53     阅读(754)     评论(0)     点赞(2)     收藏(5)


0

1

2

3

4

5

6

7

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. can someone help!!


解决方案


the pygame.mixer.music.play() is not blocking. 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

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

0

1

2

3

4

5

6

7



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/879594/d4b17f8e10502e5ab9e2/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

2 0
收藏该文
已收藏

评论内容:(最多支持255个字符)