代码之家  ›  专栏  ›  技术社区  ›  TechnoCraft

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

  •  2
  • TechnoCraft  · 技术社区  · 10 年前

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

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

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

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

    基本上,我正在制作一个程序,可以将某些文件放在特定的 播放列表,然后打开该程序,它将全部播放 然后关闭电脑。

    到目前为止,我已经设置好启动WMP(Windows Media Player),播放播放列表,然后检测WMP是否打开,如果没有,它会关闭电脑。

    如果是,它会在循环中再次检测。

    唯一的问题是播放列表完成后关闭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
    
    1 回复  |  直到 10 年前
        1
  •  1
  •   theB    10 年前

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

    至少有四个选项可用。

    1. 如果您想继续使用Windows Media Player,可以编写一个嵌入Windows Media PlayerActiveX控件的基本应用程序。(大概有100-150行代码,大部分是创建项目时自动生成的样板文件。)
    2. 使用VLC并添加 vlc://quit 播放列表的末尾。

      #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"
      
    3. 使用AutoIt等实用程序通过其用户界面控制媒体播放器实例。

    4. 使用/修改 ScriptableWMPlayer 我写的。它嵌入了Windows Media Player ActiveX控件,并具有一些基本的命令行控件。

    1. As of 2011 党的官方立场是,这是故意的。

    2. 欢迎拉取请求和错误报告。