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


Groups > comp.lang.python > #72934

Re: Automating windows media player on win7

Date 2014-06-08 00:02 +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>
Newsgroups comp.lang.python
Message-ID <mailman.10865.1402182142.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

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-06-08 00:02 +0100

csiph-web