Playing an .mov, .avi etc. file??

Alex Martelli aleaxit at yahoo.com
Thu Jan 4 11:14:20 EST 2001


"Markus von Ehr" <vonehr at ira.uka.de> wrote in message
news:3A545966.F8794D69 at ira.uka.de...
>
> harrc at my-deja.com wrote:
> >
> > Does anyone know of a good way from Python to play a video file (.avi
> > or .mpg or .mov)?  Or even better, a way to play slected tracks off a
    [snip]
> On windows systems you can use the win32com module and use OLE/COM
> control mechanism. I tried to use MediaPlayer, but had problems.
> If you use windows and COM control, please answer in case of success.

Here's a quickie that works for me, though, as I mentioned, I don't
have a working soundcard, so I'm running it with a videofile instead.

As I suggested in a previous message, doing it through Internet
Explorer is generally the easiest way to instantiate an Active/X
Control on Windows.  Of course, for better control on the user
interface, one would (e.g.) write this as an HTA (HTML Application)
with the correct attributes, and/or hide the uneeded IE controls,
resize the window around the video being displayed, etc -- but, that
would take me more than the 5 minutes it took to put this together...:

import time, win32com.client.gencache

ie = win32com.client.gencache.EnsureDispatch(
    "InternetExplorer.Application")
ie.Navigate(r'about:blank')

doc = ie.Document
doc.body.insertAdjacentHTML("afterBegin",
"""
<OBJECT ID="MediaPlayer1"
    CLASSID="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95">
</OBJECT>
""")

mp = doc.body.children("MediaPlayer1").object

mp.FileName = r"D:\Videos\AVideo.m1v"
print mp.ReadyState,mp.Duration

ie.Visible=1

mp.Play
time.sleep(mp.Duration)

ie.Quit()


Alex






More information about the Python-list mailing list