0
我正在尝试编写一个简单的音乐播放器。出于某种原因,我选择一个mp3文件并点击播放按钮后,没有声音发生。没有错误,没有。它似乎直接跳过命令。任何人都知道为什么它可能会这样做?如果有更好的方式用python播放音乐,它是什么?简单的音乐播放器不会播放
from win32com.client import Dispatch
import Tkinter
import tkFileDialog
class PlayerWin (Tkinter.Tk) :
def __init__ (self) :
self.Dir = None
Tkinter.Tk.__init__(self)
Tkinter.Button(self, text='File', command=self.select_file).pack()
Tkinter.Button(self, text=' ► ', command=self.play ,font=('Arial', 10 ,'bold')).pack()
def select_file (self) :
_dir = tkFileDialog.askopenfilename()
self.Dir = _dir
def play (self) :
mp = Dispatch('WMPlayer.OCX')
if self.Dir != None :
print self.Dir
song = mp.newMedia(self.Dir)
mp.currentPlaylist.appendItem(song)
mp.controls.play()
if __name__ == '__main__' :
PlayerWin().mainloop()
它是否成功'打印self.Dir'? – 2011-05-10 05:32:40
如果您手动调用播放,那么它工作吗? – 2011-05-10 05:34:39
对两者都是。我怀疑它与在.mainloop()方法中调用有关。 – rectangletangle 2011-05-10 05:37:36