win32com, COM, MediaPlayer

Alex Martelli aleaxit at yahoo.com
Wed Jan 3 05:30:42 EST 2001


"Markus von Ehr" <vonehr at ira.uka.de> wrote in message
news:3A52EED5.F5F40D62 at ira.uka.de...
    [snip]
> Does anybody know why the Player doesn't appear and why the Play
> function doesn't work? (I tried w.Play=1 but that doesn't work neither)

MediaPlayer's "Open" works asynchronously -- that may be why explicit
calls to "Play" interact badly with it.  Setting the 'FileName' property,
then calling the 'Play' methods, might work better.

If you do want to work asynchronously, I think you'll have to check
(by poll, or by events) on the various 'states' involved (I'm not
sure whether OpenState, PlayState, or ReadyState governs here; alas,
MediaPlayer appears to be rather underdocumented, and I can't easily
experiment here since IsSoundCardEnabled tells me '0'...:-).

Given asynchronous operation, anyway, you surely don't want to let
your process terminate (by the controlling script "falling off the
end", as in your code) until the operations you desire are also done
(I _think_, but I'm not sure, that this also holds for the Play
verb).  Again, receiving events, or periodically polling the state
bits that interest you, are two alternatives.

Another minor issue with your code:

> w.AutoStart=1
> w.Open("c:\Programme\Python\ex1.wav")

The blackslashes have special meaning in a string; either double
them, or make this a "rawstring" by pasting an r (lowercase R)
just before the opening quote.


Alex






More information about the Python-list mailing list