Automating windows media player on win7
MRAB
python at mrabarnett.plus.com
Sat Jun 7 19:02:13 EDT 2014
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()
More information about the Python-list
mailing list