用python的pygame制作我的第一个音乐播放器

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_40840880/article/details/102642863

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

猜你喜欢

转载自blog.csdn.net/weixin_40840880/article/details/102642863