Commit 99242c21 by Administrator

Update my_music.py

parent 2aadbf28
Showing with 4 additions and 35 deletions
......@@ -13,23 +13,14 @@ last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 将文件内的音乐添加到列表
music_list=[]
path="C:\\Users\\LTT\\Documents\\pygame_lesson5_diy1\\"
file=os.listdir(path)
for i in file:
if i[-4:]==".wav" or i[-4:]==".ogg":
music_list.append(i)
# 载入音乐
#pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0
click_xy=(0,0)
play_button = stop_img
num=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -49,12 +40,6 @@ while True:
# 按下鼠标
if event.type == locals.MOUSEBUTTONDOWN:
# 获取点击处的坐标
click_xy=event.pos
click_x=click_xy[0]
click_y=click_xy[1]
# 按下音乐暂停/开始按钮处
if click_x>270 and click_x<370 and click_y>350 and click_y<450:
# 次数增加
click += 1
if click % 2 == 0:
......@@ -63,24 +48,9 @@ while True:
else:
play_button = play_img
pygame.mixer.music.pause()
# 按下上一曲
if click_x>120 and click_x<220 and click_y>350 and click_y<400:
num-=1
if num < 0:
num=len(music_list)-1
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(path+"\\"+music_list[num])
pygame.mixer.music.play()
pygame.mixer.music.play()
# 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景
......@@ -89,4 +59,4 @@ while True:
screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面
pygame.display.update()
\ No newline at end of file
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