From 4510688b5851ae5b0205104c941ba5628278361f Mon Sep 17 00:00:00 2001
From: BellCodeEditor <bellcode_dev@bell.ai>
Date: Sat, 26 Feb 2022 15:29:10 +0800
Subject: [PATCH] save project

---
 my_music.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------
 1 file changed, 80 insertions(+), 41 deletions(-)

diff --git a/my_music.py b/my_music.py
index 0310d2f..8dbd7b2 100644
--- a/my_music.py
+++ b/my_music.py
@@ -3,36 +3,40 @@ from pygame import locals
 import os
 import random
 
-pygame.init()  # 初始化
-# 创建窗口
+#Init
+pygame.init()
 screen = pygame.display.set_mode((640, 480))
-# 载入图片、资源
-bg_img = pygame.image.load('background.png')  # 背景图
-play_img = pygame.image.load('play.png')  # 播放按钮
-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')  # 下一曲按钮
+bg_img = pygame.image.load('background.png')
+play_img = pygame.image.load('play.png') 
+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') 
+f=pygame.font.Font("wula.ttc",50)
 clock=pygame.time.Clock()
-music_list = []
+
+#Search
 path = "C:\\Users\\Administrator\\Desktop\\test"
 filelist = os.listdir(path)
-num = -1
+music_list = []
 for i in filelist:
-    if i[-4:] == ".wav" or i[-4:] == ".ogg" or i[-4:] == ".mp3":
+    if i[-4:] == ".wav" or i[-4:] == ".ogg":
         music_list.append(i)
-volume = 0.2
-pygame.mixer.music.set_volume(volume)  # 初始播放音量
+
+#Special Define
+num = -1
 click = 0
-play_button = stop_img
+volume = 0.2
 angle=0
 niyuchen=0
-f2=pygame.font.Font("wula.ttc",50)
+play_button = stop_img
+pygame.mixer.music.set_volume(volume)
 while True:
     for event in pygame.event.get():
+        #So you wanna go...
         if event.type == locals.QUIT:
             exit()
-        # 按键,控制声音大小
+        #Press?
         if event.type == locals.KEYDOWN:
             if event.key == locals.K_w:
                 volume += 0.1
@@ -44,11 +48,13 @@ while True:
                 if volume < 0:
                     volume = 0
                 pygame.mixer.music.set_volume(volume)
-
+        
+        #Mouse!
         if event.type == locals.MOUSEBUTTONDOWN:
-            if event.button == 1:  # 左击
+            if event.button == 1:
                 x, y = event.pos
-                if x > 270 and x < 370 and y > 350 and y < 450: # 播放按钮
+                #Pause?
+                if x > 270 and x < 370 and y > 350 and y < 450:
                     click += 1
                     if click % 2 == 0:
                         pygame.mixer.music.unpause()
@@ -58,12 +64,15 @@ while True:
                         pygame.mixer.music.pause()
                         play_button = play_img
                         niyuchen=1
-                if x > 420 and x < 520 and y > 350 and y < 400:     # 下一曲
+                #Next
+                if x > 420 and x < 520 and y > 350 and y < 400:
                     num += 1
                     if num > len(music_list) - 1:
                         num = 0
                     pygame.mixer.music.load(path + "\\" + music_list[num])
                     pygame.mixer.music.play()
+                    sound=pygame.mixer.Sound(path+"\\"+music_list[num])
+                    s_length=sound.get_length()
                     niyuchen=0
                     angle=-0.909
                     play_button = stop_img
@@ -71,13 +80,15 @@ while True:
                         click += 2
                     else:
                         click += 1
-
-                if x > 120 and x < 220 and y > 350 and y < 400:     # 上一曲
+                #Last
+                if x > 120 and x < 220 and y > 350 and y < 400:
                     num -= 1
                     if num < 0:
                         num = len(music_list) - 1
                     pygame.mixer.music.load(path + "\\" + music_list[num])
                     pygame.mixer.music.play()
+                    sound=pygame.mixer.Sound(path+"\\"+music_list[num])
+                    s_length=sound.get_length()
                     niyuchen=0
                     angle=-0.909
                     play_button = stop_img
@@ -85,43 +96,71 @@ while True:
                         click += 2
                     else:
                         click += 1
+    #Yuchen Nee
     if niyuchen==0:
-        angle-=0.909
-        font=pygame.font.Font("wula.ttc",50)
+        angle-=0.909  #Swinging~
+        font=pygame.font.Font("wula.ttc",50)  #Present
     else:
-        font=pygame.font.Font("wul.ttc",50)
-    newlogo=pygame.transform.rotate(logo_img,angle)
-    newrect=newlogo.get_rect(center=(320,200))
-    pos=(newrect[0],newrect[1])
+        font=pygame.font.Font("wul.ttc",50)  #Past
+    
+    #Run
     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()
-    s=int(pygame.mixer.music.get_pos()//1000)
-    info=str(s//60)+":"+str(s%60)
-    print(info)
+        sound=pygame.mixer.Sound(path+"\\"+music_list[num])
+        s_length=sound.get_length()
+    
+    #T E N E T
+    now_seconds=int(pygame.mixer.music.get_pos()//1000)
+    if now_seconds % 60 < 10:
+        info=str(now_seconds // 60) + ":" + "0" + str(now_seconds % 60)
+    else:
+        info=str(now_seconds // 60) + ":" + str(now_seconds % 60)
+    whole_seconds=int(s_length)
+    if whole_seconds % 60 < 10:
+        info2="/" + str(whole_seconds // 60) + ":" + "0" + str(whole_seconds % 60)
+    else:
+        info2="/" + str(whole_seconds // 60) + ":" +str(whole_seconds % 60)
+    
+    ##Funny
+    #Colorful
     ypa=random.randint(1,12)
     first=random.randint(0,20)
     second=random.randint(0,20)
     third=random.randint(0,20)
+    #Change
     if niyuchen==0:
         text = font.render(info,True,(first*ypa,second*ypa,third*ypa))
+        text2 = font.render(info2,True,(first*ypa,second*ypa,third*ypa))
     else:
         text = font.render(info,True,(255,255,255))
-    t2 = font.render(info,False,(third*ypa,first*ypa,second*ypa))
-    # 绘制画面
-    screen.blit(bg_img, (0, 0))      # 填充背景
-    screen.blit(play_button, (270, 330))   # 暂停按钮
-    screen.blit(newlogo,pos)    # 中间logo图
-    screen.blit(last_img, (120, 350))   # 上一曲
-    screen.blit(next_img, (420, 350))   # 下一曲
+        text2 = font.render(info2,True,(255,255,255))
+    #Blind
+    chongying = font.render(info,False,(third*ypa,first*ypa,second*ypa))
+    chongying2 = font.render(info2,False,(third*ypa,first*ypa,second*ypa))
+    
+    #Ready
+    newlogo=pygame.transform.rotate(logo_img,angle)
+    newrect=newlogo.get_rect(center=(320,200))
+    pos=(newrect[0],newrect[1])
+    #Painting
+    screen.blit(bg_img, (0, 0))     
+    screen.blit(play_button, (270, 330))   
+    screen.blit(newlogo,pos)  
+    screen.blit(last_img, (120, 350)) 
+    screen.blit(next_img, (420, 350))
     if niyuchen==0:
         screen.blit(text,(ypa+20,ypa+400))
-        screen.blit(t2,(ypa+20-first,ypa+400-first))
+        screen.blit(chongying,(ypa+20-first,ypa+400-first))
+        screen.blit(text2,(ypa+153,ypa+400))
+        screen.blit(chongying2,(ypa+153-first,ypa+400-first))
     else:
         screen.blit(text,(25,400))
-    # 刷新画面
+        screen.blit(text2,(153,400))
+  
+    #Update
     clock.tick(60)
     pygame.display.update()
\ No newline at end of file
--
libgit2 0.25.0