Automating windows media player on win7

Deogratius Musiige DMusiige at sennheisercommunications.com
Wed Jul 23 05:20:37 EDT 2014


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.com at python.org] On Behalf Of Deogratius Musiige
Sent: 6. juni 2014 15:39
To: MRAB; python-list at 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.com at python.org] On Behalf Of MRAB

Sent: 4. juni 2014 21:23

To: python-list at python.org<mailto:python-list at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140723/eed64dfd/attachment.html>


More information about the Python-list mailing list