[pywin32-bugs] [ pywin32-Bugs-1226744 ] win32com: WMPlayer.OCX + threading doesn't work
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2005-06-26 12:44:11
|
Bugs item #1226744, was opened at 2005-06-24 14:12 Message generated for change (Comment added) made by mhammond You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1226744&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Invalid Priority: 5 Submitted By: thinkinfinity (thinkinfinity) Assigned to: Nobody/Anonymous (nobody) Summary: win32com: WMPlayer.OCX + threading doesn't work Initial Comment: I'm trying to create an alarm of sorts. I narrowed the problem down to this: ------------------ problem.py ------------------ #!/usr/bin/env python import threading from win32com.client import Dispatch class MPlayer: def __init__(self, filename): self.filename = filename self.mp_handle = Dispatch('WMPlayer.OCX') self.mp_handle.currentPlaylist.appendItem(self.mp_handle.newMedia(filename)) def play(self): self.mp_handle.controls.play() mplayer = MPlayer('audiofile.mp3') threading.Timer(5, mplayer.play).start() #time.sleep(5) #mplayer.play() ------------------------------------------------- It seems like I can't get any other thread than the main one to do the actual playing: Interchanging: threading.Timer(5, mplayer.play).start() with: time.sleep(5) mplayer.play() doesn't work either so its not just threads. pywin32 Build 204 Thanks ---------------------------------------------------------------------- >Comment By: Mark Hammond (mhammond) Date: 2005-06-26 22:44 Message: Logged In: YES user_id=14198 These are "features" of COM itself and nothing to do with Python. In general, you can not simply pass COM objects between threads - they must be marshalled via CoMarshalInterThreadInterfaceInStream and all other COM threading rules must be observed. In your most recent problem, the issue is almost certainly the lack of a message loop. Substitute time.sleep() for pythoncom.PumpMessages() and it is more likely to work (although you will need to press Ctrl+C, or call PostQuitMessage, to exit the message loop. ---------------------------------------------------------------------- Comment By: thinkinfinity (thinkinfinity) Date: 2005-06-24 23:30 Message: Logged In: YES user_id=1191227 Actually, now nothing is working for me except when I play it through clicking a button on a gui. For example, the following script doesn't work: #!/usr/bin/env python from win32com.client import Dispatch mp = Dispatch ("WMPlayer.OCX") TUNE = mp.newMedia ("audiofile.mp3") # here error occurrence mp.currentPlaylist.appendItem (TUNE) mp.controls.play () raw_input ("Press Enter to stop playing") mp.controls.stop () ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1226744&group_id=78018 |