Automating windows media player on win7

Deogratius Musiige DMusiige at sennheisercommunications.com
Wed Jul 23 13:55:03 CEST 2014


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.com at python.org] On Behalf Of MRAB
Sent: 23. juli 2014 12:57
To: python-list at 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



More information about the Python-list mailing list