RE: Automating windows media player on win7

2014-07-23 Thread Deogratius Musiige
Hi mate,



The fix you provided works perfect. However, if I put it in a class and import, 
make instance and execute in another file, the audio is not played.

What am I missing? This is what I do:



FileA.py
class WMPlayer():
'''
@
'''
#static var
#first instance is a primary , following are secondary.
#you can have one primary and as many secondary as you like
def __init__(self):
'''
init all attributes
'''
#self.mp = Dispatch(WMPlayer.OCX)
#pass

def play_song(self):
mp = Dispatch(WMPlayer.OCX)
tune = mp.newMedia(r./SleepAway.mp3)
mp.currentPlaylist.appendItem(tune)
mp.controls.play()
sleep(1)
mp.controls.playItem(tune)
raw_input(Press Enter to stop playing)
#sleep(5)

mp.controls.stop()



FileB.py

from wmp.WMPlayer import *



class sTest(unittest.TestCase):


def test_wmplayer(self):
self.wmp = WMPlayer()

self.wmp.play_song()







Best regards / Med venlig hilsen



Deogratius Musiige

Sennheiser Communications A/S

Direct +45 5618 0320





-Original Message-
From: Python-list [mailto:python-list-bounces+demu=senncom@python.org] On 
Behalf Of Deogratius Musiige
Sent: 6. juni 2014 15:39
To: MRAB; python-list@python.org
Subject: RE: Automating windows media player on win7



Thanks a lot mate.



You just made my day.

I have looked around the net but cannot find the controls available.



I would like to be able to:

- get current playing track

- get wmplayer state (playing/paused/stopped)

- get the selected sound device



Thanks a lot



Br

Deo

-Original Message-

From: Python-list [mailto:python-list-bounces+demu=senncom@python.org] On 
Behalf Of MRAB

Sent: 4. juni 2014 21:23

To: python-list@python.orgmailto:python-list@python.org

Subject: Re: Automating windows media player on win7



On 2014-06-03 09:10, Deogratius Musiige 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()



I've found that adding PlayItem and sleep seems to work:



#! python2.7

# -*- coding: utf-8 -*-

from win32com.client import Dispatch

from time import sleep



mp = Dispatch(WMPlayer.OCX)

tune = mp.NewMedia(r./plays.wav)

mp.CurrentPlaylist.AppendItem(tune)

mp.Controls.Play()

sleep(1)

mp.Controls.PlayItem(tune)

raw_input(Press Enter to stop playing)

mp.Controls.Stop()



--

https://mail.python.org/mailman/listinfo/python-list



--

https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Automating windows media player on win7

2014-07-23 Thread MRAB

On 2014-07-23 10:20, Deogratius Musiige wrote:


Hi mate,

The fix you provided works perfect. However, if I put it in a class 
and import, make instance and execute in another file, the audio is 
not played.


What am I missing? This is what I do:

I'm assuming that you're not actually calling the files FileA.py and 
FileB.py.


*FileA.py*


You need these imports:

from win32com.client import Dispatch
from time import sleep


classWMPlayer():

'''

@

'''

#static var

#first instance is a primary , following are secondary.

#you can have one primary and as many secondary as you like

def__init__(self):

'''

init all attributes

'''

#self.mp = Dispatch(WMPlayer.OCX)

#pass

defplay_song(self):

mp = Dispatch(WMPlayer.OCX)

tune = mp.newMedia(r./SleepAway.mp3)

mp.currentPlaylist.appendItem(tune)

mp.controls.play()

sleep(1)

mp.controls.playItem(tune)

raw_input(Press Enter to stop playing)

#sleep(5)

mp.controls.stop()

**

*FileB.py*


You need this import:

import unittest


**

fromwmp.WMPlayer import*

classsTest(unittest.TestCase):

deftest_wmplayer(self):

self.wmp = WMPlayer()

self.wmp.play_song()


You also need to run the test:

if __name__ == '__main__':
unittest.main()

--
https://mail.python.org/mailman/listinfo/python-list


RE: Automating windows media player on win7

2014-07-23 Thread Deogratius Musiige
Hi,
I have the mentioned imports. And for the matter of fact I can play the audio. 

The problem is when I make a class with the wmplayer automating code and make 
an instance of this class in my testing code.
When I run this instance, I do not get any audio out?

Best regards / Med venlig hilsen

Deogratius Musiige
Sennheiser Communications A/S
Direct  +45 5618 0320


-Original Message-
From: Python-list [mailto:python-list-bounces+demu=senncom@python.org] On 
Behalf Of MRAB
Sent: 23. juli 2014 12:57
To: python-list@python.org
Subject: Re: Automating windows media player on win7

On 2014-07-23 10:20, Deogratius Musiige wrote:

 Hi mate,

 The fix you provided works perfect. However, if I put it in a class 
 and import, make instance and execute in another file, the audio is 
 not played.

 What am I missing? This is what I do:

I'm assuming that you're not actually calling the files FileA.py and FileB.py.

 *FileA.py*

You need these imports:

from win32com.client import Dispatch
from time import sleep

 classWMPlayer():

 '''

 @

 '''

 #static var

 #first instance is a primary , following are secondary.

 #you can have one primary and as many secondary as you like

 def__init__(self):

 '''

 init all attributes

 '''

 #self.mp = Dispatch(WMPlayer.OCX)

 #pass

 defplay_song(self):

 mp = Dispatch(WMPlayer.OCX)

 tune = mp.newMedia(r./SleepAway.mp3)

 mp.currentPlaylist.appendItem(tune)

 mp.controls.play()

 sleep(1)

 mp.controls.playItem(tune)

 raw_input(Press Enter to stop playing)

 #sleep(5)

 mp.controls.stop()

 **

 *FileB.py*

You need this import:

import unittest

 **

 fromwmp.WMPlayer import*

 classsTest(unittest.TestCase):

 deftest_wmplayer(self):

 self.wmp = WMPlayer()

 self.wmp.play_song()

You also need to run the test:

if __name__ == '__main__':
 unittest.main()

--
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Automating windows media player on win7

2014-07-23 Thread MRAB


On 2014-07-23 12:55, Deogratius Musiige wrote:

Hi,
I have the mentioned imports. And for the matter of fact I can play the audio.

The problem is when I make a class with the wmplayer automating code and make 
an instance of this class in my testing code.
When I run this instance, I do not get any audio out?

[snip]

When I made the changes I mentioned, the code worked for me.

Could you post _all_ of the code you're trying, including the imports 
and the line that calls the test?


--
https://mail.python.org/mailman/listinfo/python-list


Re: Automating windows media player on win7

2014-06-07 Thread MRAB

On 2014-06-06 14:39, Deogratius Musiige wrote:

Thanks a lot mate.

You just made my day.
I have looked around the net but cannot find the controls available.

I would like to be able to:
- get current playing track
- get wmplayer state (playing/paused/stopped)
- get the selected sound device


[snip]
Here's a bit more. Note how it seems to need short sleeps after certain
actions (I don't know why!):

#! python2.7
# -*- coding: utf-8 -*-
import pywintypes
from win32com.client import Dispatch
from time import sleep

tunes = [./plays.wav, ./plays.wav, ./plays.wav] # Whatever

mp = Dispatch(WMPlayer.OCX)

for name in tunes:
tune = mp.NewMedia(name)
mp.CurrentPlaylist.AppendItem(tune)

mp.Controls.Play()
sleep(0.25)

for i in range(len(tunes)):
print Current tune is, mp.Controls.CurrentItem.Name

print 'Playing current tune'
mp.Controls.PlayItem(mp.Controls.CurrentItem)
print 'mp.Status says', mp.Status

sleep(5)

print 'Pausing'
mp.Controls.Pause()
print 'mp.Status says', mp.Status

sleep(2)

print 'Resuming'
mp.Controls.Play()
print 'mp.Status says', mp.Status
sleep(5)

mp.Controls.Next()
sleep(0.25)

mp.Controls.Stop()

--
https://mail.python.org/mailman/listinfo/python-list


RE: Automating windows media player on win7

2014-06-06 Thread Deogratius Musiige
Thanks a lot mate. 

You just made my day. 
I have looked around the net but cannot find the controls available. 

I would like to be able to:
- get current playing track
- get wmplayer state (playing/paused/stopped)
- get the selected sound device

Thanks a lot

Br
Deo
-Original Message-
From: Python-list [mailto:python-list-bounces+demu=senncom@python.org] On 
Behalf Of MRAB
Sent: 4. juni 2014 21:23
To: python-list@python.org
Subject: Re: Automating windows media player on win7

On 2014-06-03 09:10, Deogratius Musiige 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()

I've found that adding PlayItem and sleep seems to work:

#! python2.7
# -*- coding: utf-8 -*-
from win32com.client import Dispatch
from time import sleep

mp = Dispatch(WMPlayer.OCX)
tune = mp.NewMedia(r./plays.wav)
mp.CurrentPlaylist.AppendItem(tune)
mp.Controls.Play()
sleep(1)
mp.Controls.PlayItem(tune)
raw_input(Press Enter to stop playing)
mp.Controls.Stop()

--
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Automating windows media player on win7

2014-06-06 Thread Michael Torrie
On 06/06/2014 07:39 AM, Deogratius Musiige wrote:
 Thanks a lot mate. 
 
 You just made my day. 
 I have looked around the net but cannot find the controls available. 
 
 I would like to be able to:
 - get current playing track
 - get wmplayer state (playing/paused/stopped)
 - get the selected sound device

You might want to ask on the python win32-specific mailing list.
https://mail.python.org/mailman/listinfo/python-win32

If you're not married to Windows Media Player, VLC is designed for this
sort of thing.  It's fully remoteable using a simple socket interface.

 https://github.com/CodeSturgeon/vlcrc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Automating windows media player on win7

2014-06-04 Thread MRAB

On 2014-06-03 09:10, Deogratius Musiige 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()


I've found that adding PlayItem and sleep seems to work:

#! python2.7
# -*- coding: utf-8 -*-
from win32com.client import Dispatch
from time import sleep

mp = Dispatch(WMPlayer.OCX)
tune = mp.NewMedia(r./plays.wav)
mp.CurrentPlaylist.AppendItem(tune)
mp.Controls.Play()
sleep(1)
mp.Controls.PlayItem(tune)
raw_input(Press Enter to stop playing)
mp.Controls.Stop()

--
https://mail.python.org/mailman/listinfo/python-list


Re: Automating windows media player on win7

2014-06-03 Thread Chris Angelico
On Tue, Jun 3, 2014 at 6:10 PM, Deogratius Musiige
dmusi...@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


Re: Automating windows media player on win7

2014-06-03 Thread Chris Angelico
On Tue, Jun 3, 2014 at 7:42 PM, Deogratius Musiige
dmusi...@sennheisercommunications.com wrote:
 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

Play, definitely. Next, not specifically, but by sending the letter
'n' you can achieve that. Active device? Not sure what you mean there.

The one part that doesn't exist is Get playing track. But you could
manage this the other way around, by not invoking a playlist at all.
If you run vlc --play-and-exit some_file.wav, then when that process
terminates, the track has finished. Kill the process or send Ctrl-Q to
skip to the next track. Keep track (pun intended) of what file you've
most recently invoked.

I'm not sure how this ties in with your headset testing, though.

By the look of things, the Yosemite project isn't a here it is, just
deploy it solution, but you may find that there's some useful code
you can borrow.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Automating windows media player on win7

2014-06-03 Thread Deogratius Musiige
Thanks for the good info Chris.
I'll look into the project. However, I hope that I can find a solution using 
OCX dispatch.
The dispatch provides all the functionalities I need.

Best regards / Med venlig hilsen
Deo

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

On Tue, Jun 3, 2014 at 7:42 PM, Deogratius Musiige 
dmusi...@sennheisercommunications.com wrote:
 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

Play, definitely. Next, not specifically, but by sending the letter 'n' you can 
achieve that. Active device? Not sure what you mean there.

The one part that doesn't exist is Get playing track. But you could manage 
this the other way around, by not invoking a playlist at all.
If you run vlc --play-and-exit some_file.wav, then when that process 
terminates, the track has finished. Kill the process or send Ctrl-Q to skip to 
the next track. Keep track (pun intended) of what file you've most recently 
invoked.

I'm not sure how this ties in with your headset testing, though.

By the look of things, the Yosemite project isn't a here it is, just deploy 
it solution, but you may find that there's some useful code you can borrow.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Automating windows media player on win7

2014-06-03 Thread Deogratius Musiige
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@python.org] On 
Behalf Of Chris Angelico
Sent: 3. juni 2014 10:58
Cc: python-list@python.org
Subject: Re: Automating windows media player on win7



On Tue, Jun 3, 2014 at 6:10 PM, Deogratius Musiige 
dmusi...@sennheisercommunications.commailto:dmusi...@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
-- 
https://mail.python.org/mailman/listinfo/python-list