Automating windows media player on win7

Chris Angelico rosuav at gmail.com
Tue Jun 3 04:57:35 EDT 2014


On Tue, Jun 3, 2014 at 6:10 PM, Deogratius Musiige
<DMusiige at sennheisercommunications.com> wrote:
> Hi guys,
>
>
>
> I have been fighting with automating wmplayer but with no success.
>
> It looks to me that using the .OCX would be the best option. I found the
> code below on the net but I cannot get it to work.
>
> I can see from device manager that a driver is started by I get no audio
> out.
>
> What am I doing wrong guys?
>
>
>
> # this program will play MP3, WMA, MID, WAV files via the WindowsMediaPlayer
>
> from win32com.client import Dispatch
>
> mp = Dispatch("WMPlayer.OCX")
>
> tune = mp.newMedia("./plays.wav")
>
> mp.currentPlaylist.appendItem(tune)
>
> mp.controls.play()
>
> raw_input("Press Enter to stop playing")
>
> mp.controls.stop()
>
>
>
> Br
>
> Deo

First suggestion: post plain text to this list, not HTML. You don't
need it to look like the above. :)

Secondly: Is there a particular reason that you need to be automating
Windows Media Player specifically? I have a similar project which
works by sending keystrokes, which means it works with anything that
reacts to keys; mainly, I use it with VLC. It can invoke a movie or
audio file, can terminate the process, and can send a variety of
commands via keys. It's designed to be used on a (trusted) LAN.

Code is here:
https://github.com/Rosuav/Yosemite

Once something's invoked by the Yosemite project, it simply runs as
normal inside VLC. Easy to debug audio problems, because they're
managed the exact same way. Granted, this does assume that it's given
full control of the screen (it's designed to manage full-screen video
playback; in fact, my siblings are right now watching Toy Story 3 in
the other room, using an old laptop driving a TV via S-Video, all
managed via the above project), so it may not be ideal for background
music on a computer you use for other things; but feel free to borrow
ideas and/or code from there. (And for what it's worth, I use this as
one of my sources of BGM when I'm coding - just let it invoke the
file, then manually flip focus back to what I'm doing.)

ChrisA



More information about the Python-list mailing list