Commit e6bbde1a by BellCodeEditor

save project

parent 6975ae45
Showing with 21 additions and 2 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()
...@@ -15,7 +16,13 @@ logo_img = pygame.image.load('logo.png') # 下一曲按钮 ...@@ -15,7 +16,13 @@ logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 载入音乐 # 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐 pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
path=r"C:\Users\科技馆\Desktop\src"
music_list=[]
for ele in os.listdir(path):
if ele[-4:] ==".wav"or ele[-4] ==".ogg":
music_list.append(ele)
index=0
print(os.listdir(path))
volume = 0.2 volume = 0.2
play_status = True play_status = True
button = stop_img button = stop_img
...@@ -39,7 +46,16 @@ while True: ...@@ -39,7 +46,16 @@ while True:
# 按下鼠标 # 按下鼠标
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()
...@@ -48,7 +64,10 @@ while True: ...@@ -48,7 +64,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)) # 填充背景
......
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