我写的还有一些问题:
播放一首歌之后不能播放第二首
请见谅
import pygame
import time
import os
def welcome():
print('''
*************************
* 欢迎来到酷我音乐播放器 *
*************************
''')
def select():
print('''
**************************
* 欢迎来到酷我音乐播放器! *
**************************
* 1.播放 2.暂停 *
* 3.下一曲 4.上一曲 *
* 5.增加音量 6.减少音量 *
* 7.取消暂停 0.退出 *
***************************
''')
return input("请选择您要操作的选项:")
#开始播放
def playMusic(path):
pygame.mixer.music.load(path)
pygame.mixer.music.play(1)
# print("000000000000000000000000")
# # pygame.mixer.music.queue(r"E:\python\day02\作业\韩红,林俊杰 - 飞云之下.mp3")
# # # print("4444444444")
x = 1
#暂停播放
def pasueMusic():
pygame.mixer.music.pause()
#取消暂停
def unpasueMusic():
pygame.mixer.music.unpause()
#控制音量
def switchMusic():
print("12345423")
pygame.mixer.music.load(path[x])
pygame.mixer.music.play()
def increaseMusic():
pygame.mixer.music.set_volume()
if __name__ == '__main__':
pass
#为歌曲所在目录
path2 = r"E:\python\day02\歌曲"
path1= os.listdir(r"E:\python\day02\歌曲")
path = []
#遍历路径并拼接起来
for filename in path1:
path.append(os.path.join(path2,filename))
pygame.mixer.init()
x = 0
y = 5
while True:
# welcome()
n = select()
if n == "1":
playMusic(path[x])
print("当前播放的歌曲为",os.path.basename(path[x]))
elif n =="2":
pasueMusic()
elif n == "3" :
if x != 6:
x += 1
# print(x)
pygame.mixer.music.stop()
switchMusic()
print("当前播放的歌曲为",os.path.basename(path[x]))
else:
x =6
print("最后一首!继续播放这一首")
print("当前播放的歌曲为",os.path.basename(path[x]))
elif n == "4":
if x != 0:
x -= 1
print(x)
pygame.mixer.music.stop()
switchMusic()
else:
print("继续播放这一首")
elif n == "5" :
y += 2
if y <= 10:
pygame.mixer.music.set_volume(y/10)
# print("1111111111",y)
else:
y = 10
# print("22222222222",y)
pygame.mixer.music.set_volume(y/10)
elif n == "6":
y -= 2
if y >= 0:
# print("333",y)
pygame.mixer.music.set_volume(y/10)
else:
y=0
# print("444",y)
pygame.mixer.music.set_volume(y/10)
elif n == "7":
unpasueMusic()
else:
break
```