pygame音乐播放器
哈哈 今天又了解了一个有趣的东西,是关于pygame模块播放音乐的,这里就不多说了,直接撸代码吧
import pygame,randomdef welcome():
print('''
*************************
*欢迎来到迷你音乐播放器*
*************************
''')
def select():
print('''
**************************
* 1.播放2.停止*
* 3.下一曲4.上一曲*
* 5.增大音量6.减少音量*
* 7.点播0.退出*
**************************
''')
return input("请选择您要操作的选项:")
def theSongPlay(songList,num,value):
pygame.mixer.music.load(songList[num % len(songList)])
pygame.mixer.music.play()
pygame.mixer.music.set_volume(value)def myValuePrint(value):
print('当前音量为:',(int(value*100)+1)//10*10)def mySongPlay(num):
print('当前播放歌曲为:{}'.format(songList[num]))def SongPlay(songList):
pygame.mixer.init()
value = https://www.it610.com/article/0.5
welcome()
num = random.randrange(0,len(songList))
theSongPlay(songList,num,value)
myValuePrint(value)
mySongPlay(num)
while True:
choose = select()
if choose =='3':
num += 1
theSongPlay(songList,num%len(songList),value)
mySongPlay(num%len(songList))
elif choose == '4':
num += len(songList)-1
theSongPlay(songList,num%len(songList),value)
mySongPlay(num%len(songList))
elif choose == '1':
pygame.mixer.music.unpause()
elif choose == '2':
pygame.mixer.music.pause()
elif choose == '5':
value += 0.1
if value>1:
value = https://www.it610.com/article/0
myValuePrint(value)
pygame.mixer.music.set_volume(value)
elif choose =='6':
value -= 0.1
if value<0.01 and value>0:
value = https://www.it610.com/article/0
elif value <0:
value = 1
myValuePrint(value)
pygame.mixer.music.set_volume(value)
elif choose =='7':
str = input('请输入你要点播的歌曲')
if str in songList:
num = songList.index(str)
theSongPlay(songList, num, value)
else:
print('抱歉,曲库未收录此歌')
elif choose == '0':
break
else:
print('输入非法,请重新输入')if __name__ == '__main__':
songList = ['传奇 - 王菲.mp3', '我曾 - 隔壁老樊.mp3', '我的名字 - 焦迈奇.mp3']
SongPlay(songList)
推荐阅读
- 病态与非病态的梦中人情结|病态与非病态的梦中人情结 - 草稿
- 夏天了,来一首入耳即化的音乐吧
- 爱情她死了
- 音乐那么短,但冥想的世界那么玄妙
- 四月是你的谎言(古典音乐)
- 多情总被无情扰(1)
- 2018-01-31|2018-01-31 - 草稿
- 爬取网易云音乐
- 音乐之声(二)
- FFmpeg|FFmpeg 开发(07)(FFmpeg + OpenGLES 实现 3D 全景播放器)