I run MediaPlayerClassic, as a minimized window in the taskbar (see here and the other answer too), with:
import subprocess, win32con, win32gui, win32process, win32api
info = subprocess.STARTUPINFO()
info.dwFlags = subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = win32con.SW_MINIMIZE
app = subprocess.Popen(r'c:\path\to\mpc-h64.exe "d:\mp3\song.mp3"', startupinfo=info)
It works. But sometimes, I would like to replace the currently-playing-song by another one, and I'm sending the same previous code (with another mp3).
Since MediaPlayerClassic allows only 1 instance, re-running the previous code does replace the currently-playing-song by the new one indeed, and this is what I want, so it works too. Except that the new window is no more minimized. This is probably because no new process is started: it reuses the previously existing process, and MediaPlayerClassic "opens the window" when it receives a new MP3 to play (?).
Adding:
time.sleep(0.2) # required, if not the next action happens before the MP3 changes
def callback(hwnd, hwnds):
text = win32gui.GetWindowText(hwnd)
if win32gui.GetClassName(hwnd) == 'MediaPlayerClassicW':
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
return True
win32gui.EnumWindows(callback, [])
nearly solves it, except that the window quickly flashes and then minimizes.
Question: how to relaunch a .exe already started like MediaPlayerClassic and keep it minimized? Should something else than subprocess.Popen
be used here?