开发者

MP3 Playing modules that will run within a thread Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Improve this question

I'm trying to write a program that will play MP3's. This program will also have a GUI. In order to allow both to happen simultaneously I'm implementing threading. However, I've run into a problem. Whenever I run my program everything executes normally, except no sound comes out. No errors nothing. It's as if the command was skipped. Through process of elimination I believe I've found the problem is caused when I run the music playing portion of the program from within a thread (self.MP.controls.play()).

Is anyone familiar with other modules that will allow me to play music within a thread? Or is anyone aware of what may be causing the problem?

Code:

import GUIThread as GUIT # GUIThread is just an interface I made for the threading module, just act as if it was threading.  
from win32com.client import Dispatch

class Test :
    def __init__ (self) :
        self.Dir = r'song.mp3'
        self.Thread = GUIT.Thread(self, func=self.play_song, loop=False)
        self.MP = Dispatch('WMPlayer.OCX')
        song = self.MP.newMedia(self.Dir)
        self.MP.currentPlaylist.appendItem(song)

    def start (self) :
        # Starts the thread. 
        # Equivalent to :
        # t = threading.Thread(target=self.play_song)
        # t.start()
        self.T开发者_运维技巧hread.start()

    def play_song (self) :
        # This whole function is done within the thread.

        if self.Dir != None :
            print self.Dir

            self.MP.controls.play()


    def protocol (self, val0, val1) :
        # Ignore this it's unrelated
        pass

T = Test()
T.start()

This is in Windows 7, BTW.

Edit: Also, I'm going to be using Tkinter for the GUI toolkit.


You could try pymedia or pyglet. I know pygame has mp3 support as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜