add support for FLAC music cover

develop
hnu202111020427 3 years ago
parent 5bd3121cea
commit 7395982bc5

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

@ -6,6 +6,7 @@ import time
from threading import Thread
import math
from mutagen import File
from mutagen.flac import FLAC, Picture
import sys
import win32api
#from wx.media import MediaCtrl
@ -74,6 +75,8 @@ class MainFrame(wx.Frame):
self.music = pygame.mixer.music
self.SONG_FINISHED = pygame.USEREVENT + 1
#self.createTimer()
if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
icon = wx.Icon(exeName, wx.BITMAP_TYPE_ANY)
@ -182,7 +185,7 @@ class MainFrame(wx.Frame):
# 调节音量的按钮
self.volume_slider = wx.Slider(self.play_music_panel, -1, int(self.default_volume*100), 0, 100, pos=(490, 30),
size=(-1, 80), style=wx.SL_VERTICAL|wx.SL_INVERSE)
self.volume_slider.SetToolTip(u'音量:%d%%' % self.default_volume)
self.volume_slider.SetToolTip(u'音量:%d%%' % (self.default_volume*100))
self.play_slider = wx.Slider(self.play_music_panel, -1, pos=(550, 55), size=(600, -1))
self.play_slider.SetToolTip(u'播放进度')
@ -266,7 +269,10 @@ class MainFrame(wx.Frame):
self.redraw_music_lyric_panel()
self.current_music_name = current_music_path.split('\\')[-1]
if self.current_music_name.split('.')[-1] == 'mp3':
self.get_music_cover(current_music_path)
self.get_mp3_cover(current_music_path)
self.redraw_music_cover_panel(current_music_path)
elif self.current_music_name.split('.')[-1] == 'flac':
self.get_flac_cover(current_music_path)
self.redraw_music_cover_panel(current_music_path)
else:
self.draw_music_cover_panel()
@ -284,6 +290,7 @@ class MainFrame(wx.Frame):
self.play_slider.SetRange(0, int(self.current_music_length))
self.play_slider.Bind(wx.EVT_SLIDER, self.timer)
#self.createTimer()
def play_index_music(self, music_index):
'''
@ -425,7 +432,7 @@ class MainFrame(wx.Frame):
break
time.sleep(1)
def get_music_cover(self, filepath):
def get_mp3_cover(self, filepath):
audio = File(filepath)
cover = audio.tags['APIC:'].data
write_path = filepath.split('\\')[0] + '\.tmp\cover.png'
@ -433,21 +440,42 @@ class MainFrame(wx.Frame):
with open(write_path, 'wb') as img:
img.write(cover)
def get_flac_cover(self,filepath):
audio = FLAC(filepath)
pics = audio.pictures
write_path = filepath.split('\\')[0] + '\.tmp\cover.png'
for p in pics:
if p.type == 3: # front cover
#print("\nfound front cover")
with open(write_path, "wb") as img:
img.write(p.data)
def update_total_music_time(self):
showlength = time.strftime("%M:%S", time.gmtime(int(self.current_music_length)))
play_slider_song_len = wx.StaticText(self, -1, showlength, pos=(1200, 628), size=(35, 30))
play_slider_song_len.SetOwnForegroundColour((41, 36, 33))
play_slider_song_len.Refresh()
def updatemusicslider(self):
time = self.music.get_pos()
self.play_slider.SetValue(time)
def createTimer(self,evt):
self.slider_timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.updatemusicslider,self.slider_timer)
self.slider_timer.Start(100)
#self.text_timer = wx.Timer(self)
#self.Bind(wx.EVT_TIMER, self.onUpdateText,self.text_timer)
def timer(self,evt):
obj = evt.GetEventObject()
val = obj.GetValue()
offset = self.play_slider.GetValue()
print(offset)
# self.music.load(self.current_music_path)
b = self.music.get_pos()
#print(offset)
self.music.stop()
self.music.play(loops=1, start=val)
''' def timer(self):
global flag
if ischanging:

Loading…
Cancel
Save