Commit 6e5f6344 by BellCodeEditor

save project

parent 453bd8e6
Showing with 57 additions and 28 deletions
...@@ -10,19 +10,26 @@ play_img = pygame.image.load('play.png') # 播放按钮 ...@@ -10,19 +10,26 @@ play_img = pygame.image.load('play.png') # 播放按钮
stop_img = pygame.image.load('stop.png') # 暂停按钮 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') # 页面
music_list=["歌曲1.wav","歌曲2.wav","歌曲3.wav","歌曲4.ogg"] sss=pygame.font.Font('ttf', 20)
FPS = pygame.time.Clock()
xuanzhuan=90
music_list=[]
number=-1# 载入音乐 number=-1# 载入音乐
# 载入音乐 logox=0
logoy=0
x,y=0,0 x,y=0,0
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
path="C:\\Users\\003\\Desktop\\test"
filelist=os.listdir(path)
for m in filelist:#插入音乐
if (m[-4:] == ".wav") or (m[-4:] == ".ogg"):
music_list.append(m)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
...@@ -38,34 +45,57 @@ while True: ...@@ -38,34 +45,57 @@ while True:
if volume < 0: if volume < 0:
volume = 0 volume = 0
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
if event.type==locals.MOUSEBUTTONDOWN: if event.type==locals.MOUSEBUTTONDOWN:
if event.button==1: if event.button==1:# 按下鼠标左键
if x>270 and x<370 and y>350 and y<450: x,y=event.pos
if x>270 and x<370 and y>350 and y<450:#按下暂停
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 >300 and y<400:
if x>120 and x<220 and y >350 and y<400:# 上一首
number-=1 number-=1
if number<0: if number<0:
number=len(music_list)-1 number=len(music_list)-1
pygame.mixer.music.load(path+"\\"+music_list[number]) pygame.mixer.music.load(path+"//"+music_list[number])
pygame.mixer.music.play() pygame.mixer.music.play()
if pygame.mixer.music.get_busy() == False: play_button = stop_img
number+=1 pygame.mixer.music.unpause()
click=0
if x>420 and x<520 and y >350 and y<400:# 下一首
number+=1
if number>len(music_list)-1:
number=0
pygame.mixer.music.load(path+"//"+music_list[number])
pygame.mixer.music.play()
play_button = stop_img
pygame.mixer.music.unpause()
click=0
if pygame.mixer.music.get_busy() == False:# 循环播放
if number>len(music_list)-1: if number>len(music_list)-1:
number=0 number=0
pygame.mixer.music.load(music_list[number]) pygame.mixer.music.load(music_list[number])
pygame.mixer.music.play() pygame.mixer.music.play()# 绘制画面
play_time=pygame.mixer.music.get_pos()
# 绘制画面 play_time=int(play_time/1000)
play_minute=play_time//60
play_second=play_time%60
sofo=str(play_minute)+":"+str(play_second)
logodown_img = pygame.transform.rotate(logo_img,xuanzhuan) # 页面
if play_button == stop_img:
xuanzhuan+=1
FPS.tick(60)
newRect = logodown_img.get_rect(center=(320,200))
pos=(newRect[0],newRect[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(last_img, (120, 350)) # 上一曲 screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲 screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面 screen.blit(logodown_img, (pos)) # 中间logo图
pygame.display.update() screen.blit(sss,(540,10))
\ No newline at end of file pygame.display.update()# 刷新画面
# text=play_time.render(info,True,(0,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