Search code examples
pythonsubprocesswindows-media-player

Playback Complete In Windows Media Player


I launched a subprocess to using its call method to play a video on Window Media Player.

eg. subprocess.call('"C:/Program Files (x86)/Windows Media Player/wmplayer.exe" "C:/Users/Public/Videos/Sample Videos/Wildlife.wmv"')

Now, how can I check if the playback is completed in the player for that particular video.

Is there is any direct Api available for the Windows Media Player Or there is a way to listen to the subprocess command launched using Popen

eg.

p = subprocess.Popen('"C:/Program Files (x86)/Windows Media Player/wmplayer.exe"  "C:/Users/Public/Videos/Sample Videos/Wildlife.wmv"')
# while the placback is happening
    p.wait()
# otherwise
    p.kill()

Solution

  • Direct WMP Api:

    subprocess.call('"C:/Program Files (x86)/Windows Media Player/wmplayer.exe" /play /close "C:/Users/Public/Videos/Sample Videos/Wildlife.wmv"')

    adding /play /close will do the needful.

    http://support.microsoft.com/KB/241422 for more options.

    Hope it will help someone in future.