Commit efec1b5f by BellCodeEditor

auto save

parent fbde1f6e
Showing with 16 additions and 4 deletions
import pygame import pygame
import os
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -11,15 +12,19 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮 ...@@ -11,15 +12,19 @@ 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') # 下一曲按钮
music_list = []
path = 'C:\\Users\\asus\\Desktop\\音乐专用'
filelist = os.listdir(path)
for i in filelist:
if i[-4] == ".wav" or i[-4] == ".ogg":
music_list.append(i)
# 载入音乐 # 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
volume = 0.2 volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量 pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0 click = 0
play_button = stop_img play_button = stop_img
num = -1
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -38,7 +43,7 @@ while True: ...@@ -38,7 +43,7 @@ while True:
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
if event.button = 1: if event.button == 1:
x,y = event.pos x,y = event.pos
if x < 370 and x > 270 and y < 450 and y > 350: if x < 370 and x > 270 and y < 450 and y > 350:
click += 1 click += 1
...@@ -48,8 +53,15 @@ while True: ...@@ -48,8 +53,15 @@ while True:
else: else:
play_button = play_img play_button = play_img
pygame.mixer.music.pause() pygame.mixer.music.pause()
if event.button == 1:
x,y = event.pos
if x < 220 and x > 120 and y < 450 and y > 350:
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
num += 1
if num>len(music_list)-1:
num = 0
pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.play() pygame.mixer.music.play()
# 绘制画面 # 绘制画面
......
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