Automating windows media player on win7

Deogratius Musiige DMusiige at sennheisercommunications.com
Tue Jun 3 05:42:59 EDT 2014


Hi Chris,

I want to have wmplayer as part of my automitized test for a headset via the USB HID.

I want to be able to execute some of the following operations in my python script:

1.       Play

2.       Get playing track

3.       Next

4.       Get active device

5.       ...

I am not sure if you are able to do this with your project



Best regards / Med venlig hilsen

Deo





-----Original Message-----
From: Python-list [mailto:python-list-bounces+demu=senncom.com at python.org] On Behalf Of Chris Angelico
Sent: 3. juni 2014 10:58
Cc: python-list at python.org
Subject: Re: Automating windows media player on win7



On Tue, Jun 3, 2014 at 6:10 PM, Deogratius Musiige <DMusiige at sennheisercommunications.com<mailto: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

--

https://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140603/0f18fea3/attachment.html>


More information about the Python-list mailing list