windows - 检测通过cmd播放的媒体播放器

标签 windows batch-file cmd media-player system-shutdown

如何检测媒体播放器是否已停止播放?

请为Windows Media Player回答。我需要它通过cmd\bat进行检测。

我需要做的就是在播放播放列表后关闭Windows Media Player。所以
到目前为止,我有:

start wmplayer.exe /play /playlist "NiteTime Listener Playlist"

基本上,我正在编写一个程序,可以在其中放置某些文件
在Windows Media Player中播放列表,然后打开该程序,然后播放所有
文件,然后关闭PC。

到目前为止,我已经设置了启动WMP(Windows Media Player),播放“播放列表”,然后检测WMP是否打开的功能,如果没有打开,它将关闭PC。

如果是,它将再次循环检测。

唯一的问题是播放列表完成后关闭WMP。

这是我的整个代码:
@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

最佳答案

当媒体播放停止时,Windows Media Player不支持自动关闭。1而且,它不包含用于控制或读取现有播放器进程状态的任何命令行选项。

至少有四个选项。

  • 如果要坚持使用Windows Media Player,则可以编写一个嵌入Windows Media Player ActiveX控件的基本应用程序。 (大约有100-150行代码,大部分是在创建项目时自动生成的样板。)
  • 使用VLC并将vlc://quit添加到播放列表的末尾。

    m3u播放列表
    #EXTM3U
    C:\Path\To\My\Media\File1.mp3
    C:\Path\To\My\Media\File2.mp3
    vlc://quit
    

    XSPF播放列表
    <?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>
    

    使用命令行启动VLC:
    start /wait "C:\path\to\vlc.exe" "c:\path\to\playlist\file.m3u"
    
  • 使用AutoIt之类的实用程序通过其用户界面控制媒体播放器实例。
  • 使用/修改我编写的ScriptableWMPlayer。它嵌入Windows Media Player ActiveX控件,并具有一些基本的命令行控件。2


  • 1 As of 2011官方的官方说法是,这是设计使然。

    2欢迎提出请求和错误报告。

    关于windows - 检测通过cmd播放的媒体播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38173664/

    相关文章:

    Windows Phone SDK 8.0 在 Windows 8 上的安装问题

    java - 如何在批处理文件中引用属性文件

    powershell - 使用powershell批量设置变量

    windows - 有没有一种简单的方法可以从嵌套的批处理脚本中捕获错误代码 (%errorlevel%)?

    r - 使用 cmd 中的参数调用 R 函数

    windows - 如何从 Windows 批处理文件中的 ECHO 字符串中去除引号?

    windows - 无法在 Eclipse 中运行 junit 测试

    batch-file - 如何在原始DOS中获得2个数字的总和?

    java - 如何从java停止wscript.exe以停止mysql服务器?

    windows - GetWindowsVersionEx 函数在 Windows 2012 R2 中输出错误