[python-win32] making Windows Media Player visible & catching events

Bill Eldridge dcbill at volny.cz
Wed Aug 3 03:59:40 CEST 2005


I'm trying to make Windows Media Player visible
and control it from Python - especially to restart
it when there's an error event. It seems when I call it
below, I get only the console version, and there's
no Visible method like with Internet Explorer.
I do catch events, but I need it visible.
Should it be put into a panel instead?
Should a different type dispatch be called
or a different method? it seems that there are
a console and a windows classes in the COM browser,
but I can't seem to access any useful windows classes,
and the methods available related to Visible are
gets, not puts/sets.

I get "fullScreen" as False, but can't set it.
openPlayer(address) will launch a visible window,
but with no control of the the window/events after that.

Any ideas?

Thanks,
Bill


from win32com.client import Dispatch,DispatchWithEvents

class WMPEvents:
    def OnVisible(self,evt):
        print "OnVisible changed:",evt
    def OnError(self,evt=None):
        print "OnError",evt
    def OnMediaError(self,evt=None):
        print "OnMediaError",evt
    def OnDisconnect(self,evt):
        print "OnDisconnect",evt
    def OnStatusChange(self):
        print "OnStatusChange"
    def OnDisconnect(self,evt):
        print "Disconnect",evt
    def OnBuffering(self,evt):
        print "OnBuffering changed:",evt
    def OnOpenStateChange(self,evt=None):
        print "OnOpenStateChange" ,evt

mp = DispatchWithEvents("WMPlayer.OCX.7",WMPEvents)
mp.Visible = True   # Does nothing
tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma")
mp.currentPlaylist.appendItem(tune)
mp.controls.playItem(tune)
mp.controls.play()
raw_input("Press enter to stop playing")
mp.controls.stop()





More information about the Python-win32 mailing list