1.代码如下:
import pygame,sys
pygame.init()
pygame.mixer.init()
screencaption=pygame.display.set_caption(‘My first music window’)
screen=pygame.display.set_mode([640,480])
screen.fill([100,150,200])
pygame.time.delay(1000)
pygame.mixer.music.load(“1.mp3”)
pygame.mixer.music.play()
while 1:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
if not pygame.mixer.music.get_busy():
soundwav.play()
pygame.time.delay(5000)
sys.exit()
import mp3play
filename = r’/usr/bin/pythonxgj/test.py\1.mp3’
clip = mp3play.load(filename)
clip.play()
import time
time.sleep(min(30, clip.seconds()))
clip.stop()
2.注意音乐叫:1.mp3 #(梦然 - 爱到尽头也无悔),放在这个目录下
/usr/bin/pythonxgj/test.py\1.mp3
3.代码的文件叫 121.py
4.执行:
xgj@xgj-PC:~$ su
密码:
root@xgj-PC:/home/xgj# cd
root@xgj-PC:~# cd /usr/bin/pythonxgj/test.py
root@xgj-PC:/usr/bin/pythonxgj/test.py# python3 121.py
5.效果:
完成,可以听歌了,ok