Python Forum
Python & Windows Media Player
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python & Windows Media Player
#1
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)
Reply
#2
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
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
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)
Reply
#4
Does Windows Media Player take command line arguments that let you specify files to play?
Reply
#5
https://docs.microsoft.com/en-us/windows...parameters

Quote:/Playlist PlaylistName Open the Player and play the specified playlist.
Extra likes this post
Reply
#6
This works for me using deanhystad's link
import subprocess
subprocess.call("C:\Program Files (x86)\Windows Media Player\wmplayer.exe /Playlist mymusic")
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#7
(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?
Reply
#8
You could look into threading. I'm not familiar with it though.
Extra likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#9
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().
menator01 likes this post
Reply
#10
Thanks!
That's exactly what I needed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How would I be able to detect a media player app playing a video. phpjunkie 2 593 Oct-16-2023, 02:09 PM
Last Post: phpjunkie
  Adding variable to Python code - media sentiment analysis Marietje 3 2,571 May-25-2021, 05:15 PM
Last Post: jefsummers
  Python - Import file sequence into Media Pool jensenni 1 2,154 Feb-02-2021, 05:11 PM
Last Post: buran
  Open windows media player minimised TamP 1 2,245 Aug-02-2020, 08:40 PM
Last Post: Larz60+
  MEDIA ROOT ionezation 1 2,201 Mar-29-2019, 02:43 PM
Last Post: ichabod801
  If - a media player exists? Nwb 2 2,798 Jun-15-2018, 06:40 PM
Last Post: snippsat
  Script for media content and redirect in to a file puneet102 0 2,355 May-22-2018, 12:06 PM
Last Post: puneet102
  Pyglet Media: unjustifiable memory usage hbknjr 4 4,614 Aug-20-2017, 02:08 AM
Last Post: hbknjr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020