Commit 4806eb25 by BellCodeEditor

auto save

parent b2548c51
Showing with 47 additions and 10 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
...@@ -11,16 +12,47 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮 ...@@ -11,16 +12,47 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img = pygame.image.load('last.png') # 上一曲按钮 last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮 next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮 logo_img = pygame.image.load('logo.png') # 下一曲按钮
pygame.mixer.music.load('歌曲3.wav') #导入音乐
volume=0.5 #控制音量大小的变量 volume=1 #控制音量大小的变量
pygame.mixer.music.set_volume(volume) #设置音量大小 pygame.mixer.music.set_volume(volume) #设置音量大小
click=0 #统计按下鼠标次数 click=0 #统计按下鼠标次数
button=stop_img #按钮形状 button=stop_img #按钮形状
#music_list = ['米津玄師&daoko-打上花火.MP3','Alan Walker&Coldplay-Hymn For The Weekend[Remix].MP3','OMFG-I Love You.MP3']
M_list = []
path = r'c:/Users/zw/Documents/pygame_lesson04_diy'
filelist = os.listdir(path)
for i in filelist:
if i[-4:] == '.MP3' or i[-4:] == '.ogg' or i[-4:] == '.wav':
M_list.append(i)
num = -1
while True: while True:
pygame.mixer.music.set_volume(volume) #设置音量大小 pygame.mixer.music.set_volume(volume) #设置音量大小
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.MOUSEBUTTONDOWN:
x,y = event.pos#获取坐标
if x > 270 and x < 370 and y > 350 and y < 450:
click+=1
if x > 120 and x < 220 and y > 350 and y < 400:
num -=1
if num<0:
num>len(M_list)-1
pygame.mixer.music.load(path+'\\'+M_list[num])
pygame.mixer.music.play()
play_button= stop_img
click = 0
if x > 420 and x < 520 and y > 350 and y < 400:
num +=1
if num>len(M_list)-1:
num = 0
pygame.mixer.music.load(path+'\\'+M_list[num])
pygame.mixer.music.play()
play_button= stop_img
click = 0
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() #退出程序 exit() #退出程序
...@@ -33,15 +65,20 @@ while True: ...@@ -33,15 +65,20 @@ while True:
volume-=0.1 volume-=0.1
if volume<0: if volume<0:
volume=0 volume=0
if event.type == locals.MOUSEBUTTONDOWN: if click%2==0:
click+=1 button=stop_img
if click%2==0: pygame.mixer.music.unpause()
button=stop_img if click%2==1:
pygame.mixer.music.unpause() button=play_img
else: pygame.mixer.music.pause()
button=play_img
pygame.mixer.music.pause()
if pygame.mixer.music.get_busy()==False: #判断音乐是否播放 if pygame.mixer.music.get_busy()==False: #判断音乐是否播放
num += 1
if num > len(M_list)-1:
num = 0
pygame.mixer.music.load(path + '\\' + M_list[num])
pygame.mixer.music.play()#播放音乐 pygame.mixer.music.play()#播放音乐
# 绘制画面 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
......
File deleted
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment