|
|
@ -6,6 +6,7 @@ import time
|
|
|
|
from threading import Thread
|
|
|
|
from threading import Thread
|
|
|
|
import math
|
|
|
|
import math
|
|
|
|
from mutagen import File
|
|
|
|
from mutagen import File
|
|
|
|
|
|
|
|
from mutagen.flac import FLAC, Picture
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import win32api
|
|
|
|
import win32api
|
|
|
|
#from wx.media import MediaCtrl
|
|
|
|
#from wx.media import MediaCtrl
|
|
|
@ -73,6 +74,8 @@ class MainFrame(wx.Frame):
|
|
|
|
pygame.mixer.init()
|
|
|
|
pygame.mixer.init()
|
|
|
|
self.music = pygame.mixer.music
|
|
|
|
self.music = pygame.mixer.music
|
|
|
|
self.SONG_FINISHED = pygame.USEREVENT + 1
|
|
|
|
self.SONG_FINISHED = pygame.USEREVENT + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#self.createTimer()
|
|
|
|
|
|
|
|
|
|
|
|
if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
|
|
|
|
if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe":
|
|
|
|
exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
|
|
|
|
exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
|
|
|
@ -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),
|
|
|
|
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)
|
|
|
|
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 = wx.Slider(self.play_music_panel, -1, pos=(550, 55), size=(600, -1))
|
|
|
|
|
|
|
|
|
|
|
|
self.play_slider.SetToolTip(u'播放进度')
|
|
|
|
self.play_slider.SetToolTip(u'播放进度')
|
|
|
@ -266,7 +269,10 @@ class MainFrame(wx.Frame):
|
|
|
|
self.redraw_music_lyric_panel()
|
|
|
|
self.redraw_music_lyric_panel()
|
|
|
|
self.current_music_name = current_music_path.split('\\')[-1]
|
|
|
|
self.current_music_name = current_music_path.split('\\')[-1]
|
|
|
|
if self.current_music_name.split('.')[-1] == 'mp3':
|
|
|
|
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)
|
|
|
|
self.redraw_music_cover_panel(current_music_path)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.draw_music_cover_panel()
|
|
|
|
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.SetRange(0, int(self.current_music_length))
|
|
|
|
self.play_slider.Bind(wx.EVT_SLIDER, self.timer)
|
|
|
|
self.play_slider.Bind(wx.EVT_SLIDER, self.timer)
|
|
|
|
|
|
|
|
#self.createTimer()
|
|
|
|
|
|
|
|
|
|
|
|
def play_index_music(self, music_index):
|
|
|
|
def play_index_music(self, music_index):
|
|
|
|
'''
|
|
|
|
'''
|
|
|
@ -425,7 +432,7 @@ class MainFrame(wx.Frame):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
def get_music_cover(self, filepath):
|
|
|
|
def get_mp3_cover(self, filepath):
|
|
|
|
audio = File(filepath)
|
|
|
|
audio = File(filepath)
|
|
|
|
cover = audio.tags['APIC:'].data
|
|
|
|
cover = audio.tags['APIC:'].data
|
|
|
|
write_path = filepath.split('\\')[0] + '\.tmp\cover.png'
|
|
|
|
write_path = filepath.split('\\')[0] + '\.tmp\cover.png'
|
|
|
@ -433,21 +440,42 @@ class MainFrame(wx.Frame):
|
|
|
|
with open(write_path, 'wb') as img:
|
|
|
|
with open(write_path, 'wb') as img:
|
|
|
|
img.write(cover)
|
|
|
|
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):
|
|
|
|
def update_total_music_time(self):
|
|
|
|
showlength = time.strftime("%M:%S", time.gmtime(int(self.current_music_length)))
|
|
|
|
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 = wx.StaticText(self, -1, showlength, pos=(1200, 628), size=(35, 30))
|
|
|
|
play_slider_song_len.SetOwnForegroundColour((41, 36, 33))
|
|
|
|
play_slider_song_len.SetOwnForegroundColour((41, 36, 33))
|
|
|
|
play_slider_song_len.Refresh()
|
|
|
|
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):
|
|
|
|
def timer(self,evt):
|
|
|
|
obj = evt.GetEventObject()
|
|
|
|
obj = evt.GetEventObject()
|
|
|
|
val = obj.GetValue()
|
|
|
|
val = obj.GetValue()
|
|
|
|
offset = self.play_slider.GetValue()
|
|
|
|
offset = self.play_slider.GetValue()
|
|
|
|
print(offset)
|
|
|
|
#print(offset)
|
|
|
|
# self.music.load(self.current_music_path)
|
|
|
|
|
|
|
|
b = self.music.get_pos()
|
|
|
|
|
|
|
|
self.music.stop()
|
|
|
|
self.music.stop()
|
|
|
|
self.music.play(loops=1,start=val)
|
|
|
|
self.music.play(loops=1, start=val)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
''' def timer(self):
|
|
|
|
''' def timer(self):
|
|
|
|
global flag
|
|
|
|
global flag
|
|
|
|
if ischanging:
|
|
|
|
if ischanging:
|
|
|
|