我一直在尝试做一个简单的播放列表,播放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
你试过了吗游戏机。混音器。音乐.queue('下一个_歌曲.mp3'). 我听说这是一首曲子,是在当前一首曲子结束后演奏的。我是python的新手。昨天开始:)
检查下面的链接,您可能会得到一个想法http://www.nerdparadise.com/tech/python/pygame/basics/part3/
在列表.pop()返回列表中的最后一项。 如果你改变了:
到
^{pr2}$那么它就可以正常工作了。在
相关问题 更多 >
编程相关推荐