|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 南城顾她 于 2018-3-22 20:51 编辑
import pygame
from pygame.locals import *
import sys
from threading import Thread
import time
LRC = ''
class LrcWord(Thread):
def __init__(self, content):
super().__init__()
self.content = content
self.daemon = True
def run(self):
global LRC
start_time = time.time()
for word in self.content:
word = word.split(']')
if len(word) > 1:
str_time = word[0].strip('[')
minute, sec = str_time.split(':')
time2 = float(minute) * 60 + float(sec)
stop_time = time.time()
time.sleep(time2 - (stop_time - start_time))
LRC = word[1]
if __name__ == '__main__':
f = open('赵照-你就是我最想要的丫头.lrc', 'r', encoding='gbk')
content = f.readlines()
Lrc = LrcWord(content)
Lrc.start()
pygame.init()
size = width, height = 800, 538
bg = (0, 0, 0)
clock = pygame.time.Clock()
END_EVENT = pygame.USEREVENT + 1
pygame.mixer.music.set_endevent(END_EVENT)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('音乐播放器')
image = pygame.image.load('赵照.jpg')
image = pygame.transform.rotozoom(image, 0, 1.8)
position = image.get_rect()
music = pygame.mixer.music.load('赵照 - 你就是我最想要的丫头.mp3')
pygame.mixer.music.play(1)
font = pygame.font.SysFont('microsoftyaheimicrosoftyaheiui', 32)
screen.fill(bg)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == END_EVENT:
pygame.quit()
sys.exit()
info = font.render(LRC, True, (0, 255, 0))
rect = info.get_rect()
rect.center = (400, 500)
screen.fill(bg)
screen.blit(image, position)
screen.blit(info, rect)
pygame.display.flip()
clock.tick(60)
|
|