From 14028a7013c94a1f6895a84b7b15e62173b92fbe Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sat, 16 Jan 2021 12:21:44 +0800 Subject: [PATCH] save project --- my_music.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/my_music.py b/my_music.py index 50cd910..6388218 100644 --- a/my_music.py +++ b/my_music.py @@ -1,5 +1,6 @@ import pygame from pygame import locals +import os pygame.init() # 初始化 # 创建窗口 @@ -11,9 +12,15 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮 last_img = pygame.image.load('last.png') # 上一曲按钮 next_img = pygame.image.load('next.png') # 下一曲按钮 logo_img = pygame.image.load('logo.png') # 下一曲按钮 +music_list=[] +num=-1 +path='C:\\Users\\pastt\\Desktop\\新建文件夹' +filelist=os.listdir(path) +for i in filelist: + if i[-4:]=='.ogg' or i[-4:]=='.wav': + music_list.append(i) # 载入音乐 -pygame.mixer.music.load('歌曲4.ogg') # 载入音乐 volume = 0.2 pygame.mixer.music.set_volume(volume) # 初始播放音量 @@ -38,15 +45,30 @@ while True: pygame.mixer.music.set_volume(volume) if event.type == locals.MOUSEBUTTONDOWN: - click += 1 - if click % 2 == 0: - play_button = stop_img - pygame.mixer.music.unpause() - else: - play_button = play_img - pygame.mixer.music.pause() + if event.button==1: + x,y=event.pos + if x>270 and x<370 and y>350 and 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 x>420 and x<520 and y<400 and y>350: + num+=1 + if num>len(music_list)-1: + num=0 + pygame.mixer.music.load(path+'\\'+music_list[num]) + pygame.mixer.music.play() + click=0 + play_button=stop_img if pygame.mixer.music.get_busy() == False: + num+=1 + if num>len(music_list)-1: + num=0 + pygame.mixer.music.load(music_list[num]) pygame.mixer.music.play() # 绘制画面 -- libgit2 0.25.0