from tkinter import *
from traceback import *
from win32com.client import Dispatch
import time,eyed3,threading
name = []
def openfile(index = [1]):
global total,name
filenames = filedialog.askopenfilenames(title = "音乐播放器",filetypes =[("mp3文件","*.mp3"),("WMA文件","*.wma"),("WAV文件","*.wav")])
if filenames:
for i in range(len(filenames)):
media = wmp.newMedia(filenames[i])
wmp.currentPlaylist.appendItem(media)
print(filenames[i])
coco = eyed3.load(filenames[i])#eyed3模块读取mp3信息
total = int(coco.info.time_secs)
minute = int(coco.info.time_secs)//60
sec = int(coco.info.time_secs)%60
length = int(coco.info.time_secs)
name = filenames[i].split("/")
i =index[-1] list_name.insert(END,str(i)+"."+name[-1])
list_name.insert(END," "*6)
if sec >=10:
list_name.insert(END,"0%d:%d" %(minute,sec)+ "n")
else:
list_name.insert(END,"0%s:0%d" %(minute,sec)+ "n")
i = i +1
index.append(i)
def play(event = None):
#root.title("%s" % name[-1]),使用wmp.currentMedia.name更好,在per函数中
per_thread = threading.Thread(target = per)
per_thread.daemnon = True
wmp.controls.play()
per_thread.start()
#print(wmp.currentMedia.duration)#放到暂停那里居然可以用,而这里不行
def per():
global total
while wmp.playState !=1:
progress_scal.set(int(wmp.controls.currentPosition))
progress_scal.config(label = wmp.controls.currentPositionString)
progress_scal.config(to = total,tickinterval = 50)
time.sleep(1)
root.title("%s" % wmp.currentMedia.name)
def stop():
wmp.controls.stop()
def pause(event = None):
wmp.controls.pause()
def uselist():
pass
def fullscr():
pass
def exitit():
root.destroy()
def Previous_it():
wmp.controls.previous()
def Next_it():
wmp.controls.next()
def Volume_ctr(none):
wmp.settings.Volume = vio_scale.get()
def Volume_add(i=[0]):
wmp.settings.Volume =wmp.settings.Volume+5
i.append(wmp.settings.Volume)
vio_scale.set(wmp.settings.Volume)
def Volume_minus(i=[0]):
wmp.settings.Volume = wmp.settings.Volume -5
i.append(wmp.settings.Volume)
vio_scale.set(wmp.settings.Volume)
def Scale_ctr(none):
wmp.controls.currentPosition = var_scale.get()
print(wmp.currentMedia.duration)
def Clear_list():
wmp.currentPlaylist.clear()
list_name.delete(1.0,END)
name = [] index = []def List_random():
wmp.settings.setMode("shuffle",True)
play()
def List_loop():
wmp.settings.setMode("loop",True)