From 362d427f39072957dfb8a55b8f817dfe8e76f13d Mon Sep 17 00:00:00 2001
From: BellCodeEditor <bellcode_dev@bell.ai>
Date: Tue, 6 Apr 2021 19:19:08 +0800
Subject: [PATCH] auto save

---
 my_music.py | 47 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/my_music.py b/my_music.py
index 44dbb1c..a5c9c6a 100644
--- a/my_music.py
+++ b/my_music.py
@@ -1,5 +1,6 @@
 import pygame
 from pygame import locals
+import os
 
 pygame.init()  # 初始化
 # 创建窗口
@@ -13,13 +14,19 @@ next_img = pygame.image.load('next.png')  # 下一曲按钮
 logo_img = pygame.image.load('logo.png')  # 下一曲按钮
 
 # 载入音乐
-
-music_list = ['歌曲1.wav','歌曲2.wav','歌曲3.wav','歌曲4.ogg']   # 载入音乐      
+path = r"C:\Users\86186\Desktop\test"
+music_list = os.listdir(path)  # 载入音乐
+music_real =[]
+for n in music_list:
+    if n[-4:] == ".wav" or n[-4:] ==  ".ogg":
+        music_real.append(n)
+print(music_real)
 
 volume = 0.2
 pygame.mixer.music.set_volume(volume)  # 初始播放音量
 click = 0
-i = -1
+i = 0
+angle = 0
 play_button = stop_img
 
 while True:
@@ -52,18 +59,44 @@ while True:
                     else:
                         play_button = play_img
                         pygame.mixer.music.pause()
+                if x >120 and x < 220 and y >350 and y <400:
+                    i -= 1
+                    if i <0:
+                        i = len(music_real) - 1 
+                    
+                    pygame.mixer.music.load(path + "//" +music_real[i])
+                    pygame.mixer.music.play()
+                    click = 0 
+                    play_button = stop_img
+                if x >420 and x < 520 and y >350 and y <400:
+                    i += 1
+                    if i >len(music_real)-1:
+                        i =  0
+                    
+                    pygame.mixer.music.load(path + "//" +music_real[i])
+                    pygame.mixer.music.play()
+                    click = 0 
+                    play_button = stop_img
+                
+                
     
     if pygame.mixer.music.get_busy() == False:
-        i += 1
-        if i> len(music_list) - 1:
+        
+        if i> len(music_list) :
             i = 0
-        pygame.mixer.music.load(music_list[i])
+        pygame.mixer.music.load(path + "//" +music_real[i])
         pygame.mixer.music.play()
+        i += 1
+    new_logo =pygame.transform.rotate(logo_img,angle)
+    new_rect =new_logo.get_rect(center = (320,200))
+    if play_button == stop_img:
+        angle += 1
+    pos = new_rect[0], new_rect[1]
 
     # 绘制画面
     screen.blit(bg_img, (0, 0))      # 填充背景
     screen.blit(play_button, (270, 330))   # 暂停按钮
-    screen.blit(logo_img, (170, 60))    # 中间logo图
+    screen.blit(new_logo, (pos))    # 中间logo图
     screen.blit(last_img, (120, 350))   # 上一曲
     screen.blit(next_img, (420, 350))   # 下一曲
     # 刷新画面
--
libgit2 0.25.0