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.执行:
[email protected]:~$ su
密码:
[email protected]:/home/xgj# cd
[email protected]:~# cd /usr/bin/pythonxgj/test.py
[email protected]:/usr/bin/pythonxgj/test.py# python3 121.py

5.效果:
用python的pygame制作我的第一个音乐播放器

完成,可以听歌了,ok

相关文章:

  • 2021-06-07
  • 2021-12-24
  • 2021-05-01
  • 2021-12-15
  • 2021-12-24
  • 2021-09-22
  • 2021-10-07
  • 2021-07-31
猜你喜欢
  • 2021-09-15
  • 2022-01-21
  • 2021-11-24
  • 2021-09-29
  • 2021-04-02
  • 2021-06-20
  • 2021-04-02
相关资源
相似解决方案