[python-win32] COM works from IDLE but not when file executed from Windows Explorer

Mark Hammond mhammond at skippinet.com.au
Wed Mar 14 23:19:56 CET 2007


> Installed: Python25, pywin32-210.win32-py2.5.exe
> Being new to COM, I have a simple question. When I execute
> the following
> code from within IDLE, I hear the mp3 file played out but
> when I run the
> file from Windows Explorer I get no sound (and no errors) ?
>
> I'm sure the answer is very simple !
>
> ( http://www.nabble.com/file/6954/playFile.py playFile.py ):
>
> from win32com.client import Dispatch
>
> if __name__ == "__main__":
>     mp = Dispatch("WMPlayer.OCX")
>     tune = mp.newMedia('my_file.mp3')
>     mp.currentPlaylist.appendItem(tune)
>     mp.controls.play()
>     raw_input("Press Enter to stop playing")
>     mp.controls.stop()

In addition to Tim's suggestion, try replacing the last 2 lines with:

    import pythoncom
    pythoncom.PumpMessages()

You will need to press Ctrl+C to terminate the script, but if the sound
plays, it means your original code does not have a message loop (while IDLE
does).  google for python and message loop and you should find lots of
messages with more detail.

Mark



More information about the Python-win32 mailing list