Commit 1120bd20 by BellCodeEditor

auto save

parent 1754f9f4
Showing with 61 additions and 12 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
...@@ -11,14 +12,22 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮 ...@@ -11,14 +12,22 @@ 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') # 下一曲按钮
my_music = []
mu = os.listdir('C:\\text')
for i in mu:
if '.wav' in i or '.ogg' in i:
my_music.append(i)
# 载入音乐 # 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐 # 载入音乐
num = -1
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
angle = 0
font = pygame.font.Font('neuropol.ttf',10)
max_time = 0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -39,23 +48,63 @@ while True: ...@@ -39,23 +48,63 @@ while True:
# 按下鼠标 # 按下鼠标
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
# 次数增加 if event.button == 1:
click += 1 x , y = event.pos
if click % 2 == 0: if 270 < x < 370 and 350 < y < 450: # 次数增加
click += 1
if click % 2 == 0:
play_button = stop_img
pygame.mixer.music.unpause()
else:
play_button = play_img
pygame.mixer.music.pause()
if 120 < x < 220 and 350 < y < 400:
num -= 1
if num < 0:
num = len(my_music) - 1
pygame.mixer.music.load('C:\\text\\'+my_music[num])
pygame.mixer.music.play()
music = pygame.mixer.Sound('C:\\text\\'+my_music[num])
max_time = int(music.get_length())
click = 0
play_button = stop_img
if 420 < x < 520 and 350 < y < 400:
num += 1
if num > len(my_music) - 1:
num = 0
pygame.mixer.music.load('C:\\text\\'+my_music[num])
pygame.mixer.music.play()
music = pygame.mixer.Sound('C:\\text\\'+my_music[num])
max_time = int(music.get_length())
click = 0
play_button = stop_img play_button = stop_img
pygame.mixer.music.unpause()
else:
play_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(mu)-1:
num = 0
pygame.mixer.music.load('C:\\text\\'+my_music[num])
pygame.mixer.music.play() pygame.mixer.music.play()
music = pygame.mixer.Sound('C:\\text\\'+my_music[num])
# 绘制画面 max_time = int(music.get_length())
play_time = pygame.mixer.music.get_pos()
play_time = int(play_time/1000)
info = str(play_time//60) + ":" + str(play_time%60)
newfont = font.render(info,True,(255,255,255))
info1 = "/" + str(max_time//60) + ":" + str(max_time%60)
newfont1 = font.render(info1,True,(0,0,0))
if play_button == stop_img:
new_loge = pygame.transform.rotate(logo_img,angle)
new_rect = new_loge.get_rect(center = (320,200))
pos = (new_rect[0], new_rect[1])
angle += 1
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮 screen.blit(play_button, (270, 330)) # 暂停按钮
screen.blit(logo_img, (170, 60)) # 中间logo图 screen.blit(new_loge, pos) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲 screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲 screen.blit(next_img, (420, 350)) # 下一曲
screen.blit(newfont,(120,440))
screen.blit(newfont1,(170,440))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
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