我一直试图制作一个简单的播放列表,一个接一个地播放3首歌曲,下面的代码显示了这一点。而不是播放第一首歌music1.mp3,它播放最后一首歌music3.mp3并停止播放。我试过看类似的问题但是想找到一个解决方案。
如果有人能帮忙给我一些建议或指导,我们将不胜感激。
麦克
更新 - 它确实播放了第一首歌但仍然没有播放下一首歌
import pygame
import time
pygame.mixer.init()
pygame.display.init()
screen = pygame.display.set_mode ( ( 420 , 240 ) )
playlist = list()
playlist.append ( "music1.mp3" )
playlist.append ( "music2.mp3" )
playlist.append ( "music3.mp3" )
pygame.mixer.music.load ( playlist.pop() ) # Get the first track from the playlist
pygame.mixer.music.queue ( playlist.pop() ) # Queue the 2nd song
pygame.mixer.music.set_endevent ( pygame.USEREVENT ) # Setup the end track event
pygame.mixer.music.play() # Play the music
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.USEREVENT: # A track has ended
if len ( playlist ) > 0: # If there are more tracks in the queue...
pygame.mixer.music.queue ( playlist.pop() ) # Queue the next one in the list