简单的音乐播放器无法播放

发布于 2024-11-06 10:08:41 字数 911 浏览 7 评论 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()

I'm trying to write a simple music player. For some reason after I select a mp3 file and hit the play button, no sound occurs. No error, nothing. It seems to skip right over the command. Anyone know why it may be doing this? If there is a better way to play music with python, what is it?

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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

噩梦成真你也成魔 2024-11-13 10:08:41

这可能与线程有关。

无论如何,还有其他适用于 Python 的 GUI 工具包,例如 WxPython,并且有一些用 Python 编写的 mp3 播放器应用程序可供您研究。

This probably has something to do with threading.

In any case, there are other GUI toolkits for Python, such as WxPython, and there are mp3 player apps written in Python that you could study.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文