Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72656 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2014-06-04 20:23 +0100 |
| Last post | 2014-06-04 20:23 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Automating windows media player on win7 MRAB <python@mrabarnett.plus.com> - 2014-06-04 20:23 +0100
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-06-04 20:23 +0100 |
| Subject | Re: Automating windows media player on win7 |
| Message-ID | <mailman.10713.1401909789.18130.python-list@python.org> |
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()
Back to top | Article view | comp.lang.python
csiph-web