需要帮助将一组歌曲加载到pygame混音器并按顺序播放吗

2024-09-26 22:09:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为学校做作业,我对python相当陌生,我需要一些关于使用pygame的帮助

这项任务是制作一个像Spotify这样的音乐库。对于库,我将所有歌曲保存在一个数组中,然后尝试将整个数组加载到pygame混音器中并尝试播放歌曲,但pygame只播放第二首歌曲。下面是我到目前为止的所有代码

from pygame import mixer
line = 
"======================================================================="
plnum = 0
songcount = 2
counter = 0
song = ""
songs = [
        "MoodyLoop.wav",
         "ShakeYourBootay.wav",
         "UpbeatFunk.wav",

        ]
cmd = ""

print(line)
print("                      welcome to soptEAify")
print(line)

print("your music library has " + str(plnum) + " playlist's with a total             of " + str(songcount) + " song's." +
  "these songs are: " + str(songs))

while cmd != "stop" :
    print(line)
    cmd = input("comand: ")


if "PLAY" in cmd or "play" in cmd:
    for elament in songs:
        if elament in cmd:
            mixer.init()
            mixer.music.load(elament)
            mixer.music.play()
elif cmd == "p" or cmd == "P" :
    mixer.music.pause()
elif cmd == "unp" or cmd == "UNP" :
    mixer.music.unpause()
elif cmd == "PA" or cmd == "pa" :
    counter = 0
    mixer.init()
    for song in songs:
        mixer.music.queue(song)
    mixer.music.play()

代码应该一首接一首地播放所有歌曲,但实际上它只播放第二首歌曲。任何帮助都将不胜感激。谢谢,这是事先准备好的


Tags: orincmdplaysonglinemusicpygame

热门问题