import wx | import platform |
import os |
import glob |
from tinytag import TinyTag |
|
|
class FFPaly(wx.Frame) : |
|
def __init__(self) : |
wx.Frame.__init__(self, None, -1, title="ffplay", size=(768, 512)) |
wx.Frame.SetMinSize(self, size=(768, 512)) |
|
self.__music_dir_path = "C:\\Music" |
self.__music_ext = ".flac" |
|
cwd = os.getcwd() |
os.chdir(self.__music_dir_path) |
music_list1 = glob.glob("*" + self.__music_ext) |
os.chdir(cwd) |
|
self.__music_file_path_list = [] |
for music1 in music_list1 : |
music_file_path = os.path.join(self.__music_dir_path, music1) |
self.__music_file_path_list.append(music_file_path) |
self.__music_file_path_list.sort() |
|
self.__create_playlist_file(self.__music_file_path_list) |
|
music_list = [] |
for music_file_path in self.__music_file_path_list : |
tag = TinyTag.get(music_file_path) |
list_item_name = "{}/{}/{:d}kHz/{:d}:{:02d}".format(tag.artist, tag.title, int(tag.samplerate / 1000), int(tag.duration / 60), int(tag.duration % 60)) |
music_list.append(list_item_name) |
|
panel1 = wx.Panel(self) |
panel1.SetBackgroundColour("#fffacd") # lemonchiffon |
panel2 = wx.Panel(self) |
panel2.SetBackgroundColour("#b0c4de") # lightsteelblue |
|
sizer = wx.BoxSizer(wx.VERTICAL) |
sizer.Add(panel1, wx.EXPAND, wx.EXPAND) |
sizer.Add(panel2, 80, wx.EXPAND) |
self.SetSizer(sizer) |
|
listBox1 = wx.ListBox(panel1, -1, choices=music_list, style=wx.LB_SINGLE | wx.LB_ALWAYS_SB) |
sizer1 = wx.BoxSizer(wx.VERTICAL) |
sizer1.Add(listBox1, 1, wx.EXPAND | wx.ALL, 20) |
panel1.SetSizer(sizer1) |
|
button1 = wx.Button(panel2, -1, label="play", size=(240, 40)) |
sizer2 = wx.BoxSizer(wx.VERTICAL) |
sizer2.Add(button1, 0, wx.ALIGN_RIGHT | wx.ALL, 20) |
panel2.SetSizer(sizer2) |
|
listBox1.SetSelection(0) |
button1.Bind(wx.EVT_BUTTON, self.OnClick1) |
|
def OnClick1(self, event) : |
if(platform.system() == "Windows") : |
command = "ffplay.exe -x 512 -y 512 -loop 0 -f concat -safe 0 -i ffplay.playlist" |
else : |
command = "ffplay -x 512 -y 512 -loop 0 -f concat -safe 0 -i ffplay.playlist" |
os.system(command) |
|
def __create_playlist_file(self, file_path_list) : |
with open("ffplay.playlist", "w", encoding="UTF-8") as f : |
f.write("ffconcat version 1.0\n\n") |
|
for line in file_path_list : |
f.write("file '{}'\n\n".format(line)) |
|
|
if __name__ == '__main__' : |
app = wx.App() |
FFPaly().Show() |
app.MainLoop() |
|