I have a small Python script that runs Windows Media Player and plays a list of music files. The files list is generated dynamically. The criteria for the list is that it should be random and a specific duration. This is working fine, and I use this to "zone in" for a specific duration of time.
The command is pretty straightforward: wmplayer.exe file1.mp3 file2.mp3 /Task MediaLibrary, and in Python:
subprocess.Popen(
cmd_args = [
wmplayer_path,
*playlist,
"/Task",
"MediaLibrary",
],
stdin=None,
stdout=None,
stderr=None,
)
Sometimes, the initial duration I set is not enough, and I want to add some more music to the playing list. To do that, I either have to wait for the play list to end and then run the script again so I get a new play list with the new/extended duration, or I should add music while the player is still running, that is the new music will be added to the existing list.
While the second method is possible in the Windows UI using the item in the context menu "Add to Windows Media Player list", I could not find a way to do this programmatically.
I checked the following pages and tried few combinations (knowing that it won't work), but couldn't make it work. There does not seem to be a way to do this.
- Command Line Parameters - Win32 apps - Microsoft Learn
- Add to WMP playlist as defaut when opening an MP3 - Windows 7 - MSFN
I came across the undocumented /Enqueue option, but whatever I tried, it didn't work.
Maybe I'm missing something, so here I am. In case there's really no way to do this, I think I'll switch to another player with advanced CLI for this kind of thing.
CLI solutions would be better, but if there are ways to do this using API in Python or C#, that's fine too.
In case it matters, I'm using Windows 10 Pro 64-bit and WMP 12.
I'm not sure if this is possible with Windows Media Player, so at least for the time being, I've decided to go with VLC for this specific functionality.
Looking at the documentation at VLC command-line help - VideoLAN Wiki, it's pretty easy to enqueue.
Calling the executable with the same options but with different files adds the new files to the currently playing list.
Another problem related to this is enqueueing items that are not already in the playing list. To do that, one needs to access the currently playing list when generating a new list of music. I've looked around and found a solution to this (using VLC).
It appears that VLC can also be controlled via http. So what I do is make a request to the VLC server, get the currently playing list, and then ignore the items in this list and generate a new unique one.