Reputation: 313
How can I detect if a media player has stopped playing?
Please answer for Windows Media Player. I need it to detect via cmd\bat.
All I need to do is close Windows Media Player after playing a playlist. so far i have:
start wmplayer.exe /play /playlist "NiteTime Listener Playlist"
Basically I'm making a program where I can place certain files in a specific playlist in Windows Media Player, and then open the program, and it play all the files, then shuts down the PC.
So far, I've set up starting WMP(Windows Media Player), playing The Playlist, then detecting if WMP is open, if it is not, it shuts down the PC.
If it is, it detects again, in a loop.
Only problem is closing WMP after playlist complete.
Here is a My Entire Code:
@echo off
title Automatic Shutdown for NiteTime Listener
echo To cancel Shutdown, close this program before Player.
start mplayer2.exe /play /Playlist "NiteTime Listener Playlist"
:testfor
tasklist /FI "IMAGENAME eq wmplayer.exe" 2>NUL | find /I /N "wmplayer.exe">NUL
if "%ERRORLEVEL%"=="0" goto :ProgramRunning
if "%ERRORLEVEL%"=="1" goto :ProgramNotRunning
pause
:ProgramRunning
goto testfor
:ProgramNotRunning
shutdown /s /f
Upvotes: 2
Views: 2283
Reputation: 6738
Windows Media Player doesn't support closing automatically when media playback stops.1 And it doesn't include any command line options for controlling or reading the status of existing player processes.
There are at least four options available.
Use VLC and add vlc://quit
to the end of your playlist.
m3u Playlist
#EXTM3U
C:\Path\To\My\Media\File1.mp3
C:\Path\To\My\Media\File2.mp3
vlc://quit
XSPF Playlist
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track><location>file:///C:\Path\To\My\Media\File1.mp3</location></track>
<track><location>file:///C:\Path\To\My\Media\File2.mp3</location></track>
<track><location>vlc://quit</location></track>
</trackList>
</playlist>
Launch VLC with the command line:
start /wait "C:\path\to\vlc.exe" "c:\path\to\playlist\file.m3u"
Use a utility like AutoIt to control the media player instance via its user interface.
1As of 2011 the official party line was that this was by design.
2Pull requests and bug reports are welcome.
Upvotes: 1