Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75077

Re: Automating windows media player on win7

Date 2014-07-23 11:57 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Automating windows media player on win7
References <A804AEE67207BF42BAF8CEC79839C8D613BF3275@kbnmxexc11.Demant.com> <538F7219.2020705@mrabarnett.plus.com> <A804AEE67207BF42BAF8CEC79839C8D613BF85BA@kbnmxexc11.Demant.com> <A804AEE67207BF42BAF8CEC79839C8D613C3320E@kbnmxexc11.Demant.com>
Newsgroups comp.lang.python
Message-ID <mailman.12232.1406113045.18130.python-list@python.org> (permalink)

Show all headers | View raw


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()

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Automating windows media player on win7 MRAB <python@mrabarnett.plus.com> - 2014-07-23 11:57 +0100

csiph-web