Commit a4e19e80 by BellCodeEditor

save project

parent 416791a9
Showing with 22 additions and 5 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import os
pygame.init() # 初始化 pygame.init() # 初始化
pygame.mixer.init() pygame.mixer.init()
...@@ -13,8 +14,15 @@ last_img = pygame.image.load('last.png') # 上一曲按钮 ...@@ -13,8 +14,15 @@ 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("test.wav")
music_list = []
path = r"C:\Users\科技馆\Desktop\src"
for ele in os.listdir(path):
if ele[-4:] == '.wav' or ele[-4:]=='.ogg':
music_list.append(ele)
print(music_list)
index = 0
volume = 0.2 volume = 0.2
play_status = True play_status = True
button = stop_img button = stop_img
...@@ -35,10 +43,18 @@ while True: ...@@ -35,10 +43,18 @@ while True:
if volume < 0: if volume < 0:
volume = 0 volume = 0
# 按下鼠标 # 按下鼠标
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
play_status = not play_status if event.button == 1:
x,y = event.pos
if x > 270 and x < 370 and y>330 and y<430:
play_status = not play_status
if x > 120 and x < 220 and y>350 and y<400:
index -= 2
pygame.mixer.music.stop()
if x > 420 and x < 520 and y>350 and y<400:
index += 0
pygame.mixer.music.stop()
if play_status == True: if play_status == True:
button = stop_img button = stop_img
pygame.mixer.music.unpause() pygame.mixer.music.unpause()
...@@ -47,9 +63,10 @@ while True: ...@@ -47,9 +63,10 @@ while True:
pygame.mixer.music.pause() pygame.mixer.music.pause()
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
pygame.mixer.music.load(path +'\\'+music_list[index%len(music_list)])
pygame.mixer.music.play() pygame.mixer.music.play()
play_status = True
# 绘制画面 index +=1 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(button, (270, 330)) # 暂停按钮 screen.blit(button, (270, 330)) # 暂停按钮
screen.blit(logo_img, (170, 60)) # 中间logo图 screen.blit(logo_img, (170, 60)) # 中间logo图
......
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