Python Forum

Full Version: Python & Windows Media Player
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I got python to launch windows media player when I say "play music" and now I'm wondering if I can have it automatically play the "Music" playlist that I have created on WMP(Windows Media Player). Because right now I have to physically click on the "Music" playlist and hit the play button.

Is there a way to do that?
If so, how?

Thanks in advance.


  #-------------------------------------------------------------------------------------
                                #Open Stuff on the Computer
    #-------------------------------------------------------------------------------------
    #Open Windows Media Player
    if ('music' in command) or ('media player' in command):
        speak('Launching Music')
        command = command.replace("music", "")
        command = command.replace("media player", "")
        musicApp = "C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
        os.startfile(musicApp)
A quick search turned up these links. May help you out.
https://stackoverflow.com/questions/2367...dia-player
Look to the bottom post on the above link
https://bytes.com/topic/python/answers/5...yer-python
So I have the path the the playlist is located:
C:\Users\BX-PC\Music\Playlists\Music

so how do I get it so my script launches windows media player and navigates to the playlist location so it can play it?

    #Open Windows Media Player
    if ('music' in command) or ('media player' in command):
        speak('Launching Music')
        command = command.replace("music", "")
        command = command.replace("media player", "")
        musicApp = "C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
        os.startfile(musicApp)
Does Windows Media Player take command line arguments that let you specify files to play?
https://docs.microsoft.com/en-us/windows...parameters

Quote:/Playlist PlaylistName Open the Player and play the specified playlist.
This works for me using deanhystad's link
import subprocess
subprocess.call("C:\Program Files (x86)\Windows Media Player\wmplayer.exe /Playlist mymusic")
(Apr-02-2022, 08:44 PM)menator01 Wrote: [ -> ]This works for me using deanhystad's link
import subprocess
subprocess.call("C:\Program Files (x86)\Windows Media Player\wmplayer.exe /Playlist mymusic")

Thanks, that worked.

Now is there any way to have my script continue running in the background, instead of waiting for me to close windows media player?
You could look into threading. I'm not familiar with it though.
subprocess.call (and the preferred subprocess.run) wait for a program to exit.

As long as you don't need to interact with WMP but just start it, you can probably get away with subprocess.Popen().
Thanks!
That's exactly what I needed.