Commit 6d011811 by BellCodeEditor

save project

parent e33b2414
Showing with 28 additions and 18 deletions
import pygame import pygame
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
screen = pygame.display.set_mode((640, 480)) screen = pygame.display.set_mode((640, 480))
...@@ -14,14 +13,8 @@ next_img = pygame.image.load('next.png') # 下一曲按钮 ...@@ -14,14 +13,8 @@ next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮 logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 载入音乐 # 载入音乐
filelist = [] filelist = ["歌曲1.wav","歌曲2.wav","歌曲3.wav","歌曲4.ogg"]
num = -1 num = -1
path = "C:\\Users\\TLTJYTM\\Desktop\\test"
file = os.listdir(path)
for i in file:
if i[-4:] == '.wav' or i[-4:] == '.ogg' or i[-4:] == '.mp3':
filelist.append(i)
volume = 0.2 volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量 pygame.mixer.music.set_volume(volume) # 初始播放音量
...@@ -50,22 +43,39 @@ while True: ...@@ -50,22 +43,39 @@ while True:
if event.button == 1: #鼠标左击 if event.button == 1: #鼠标左击
x, y = event.pos #鼠标即时位置 x, y = event.pos #鼠标即时位置
if x > 270 and x < 370 and y > 350 and y < 450: if x > 270 and x < 370 and y > 350 and y < 450:
click += 1
# 次数增加 # 次数增加
click += 1 click += 1
if click % 2 == 0: if click % 2 == 0:
play_button = stop_img play_button = stop_img
pygame.mixer.music.unpause() pygame.mixer.music.unpause()
else: else:
play_button = play_img play_button = play_img
pygame.mixer.music.pause() pygame.mixer.music.pause()
#上一曲
if x > 120 and x < 220 and y > 350 and y < 400:
num = num-1
if num < 0:
num = len(filelist)-1
pygame.mixer.music.load(filelist[num])
pygame.mixer.music.play()
click = 0
play_buttonn = stop_img
#下一曲
if x > 420 and x < 520 and y > 350 and y < 400:
num = num+1
if num > len(filelist)-1:
num = 0
pygame.mixer.music.load(filelist[num])
pygame.mixer.music.play()
click = 0
play_buttonn = stop_img
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
num += 1 num += 1
if num > len(filelist)-1: if num > len(filelist)-1:
num = 0 num = 0
pygame.mixer.music.load(path+'\\'+filelist[num]) pygame.mixer.music.load(filelist[num])
print(path+'\\'+filelist[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