Play invisible music with batch file?

2020-02-03 04:53发布

I've seen a cfew threads that say how to play music with the play minimized when it starts with start /min, as well as one that creates a VBS script to run the audio minimized. But no matter which way I try to get audio to run minimized, it appears on screen.

Also, if I try start /min or start /max I'll get the same result.

Does anyone know how I can get something to start minimized?

11条回答
一纸荒年 Trace。
2楼-- · 2020-02-03 05:20
CreateObject("Wscript.Shell").Run "wmplayer /play /close ""Your file location here""", 0, False
查看更多
唯我独甜
3楼-- · 2020-02-03 05:20

Obviously very late for the asker of the question but who knows? Someone else may look by. So I'll just reiterate Tony BD's answer from April '14, and since someone complained about it being a code only answer I'll add a little explanation and really very little is required.

1.) Open Windows Notepad

2.) Copy Tony BD's code into Notepad

3.) Substitute 'Your file location here' with the full path to the music file you want to play.

4.) In Notepad menu choose File|Save as . .

5.) Choose a location and give the file a name but ensure that instead of the standard .txt file type you give it a .vbs ending.

6.) Close Notepad

7.) Click on the vbs file you just made and your music file will start to play showing absolutely nothing on the screen.

The 0 parameter in the code enables WMP to open in an invisible window. If you change the 0 to a 1 you will see WMP's graphical interface.

Obviously this is only available for Windows users but for them it's the best and simplest solution to the problem.

查看更多
做个烂人
4楼-- · 2020-02-03 05:23

I came across this thread yesterday when I was researching a problem that I had with the solution proposed in another topic because it left the Windows Media Player open. Starting from the C code supplied by MC ND, I put together a slightly more polished and modern (wide character) version, which I just published under a three-clause BSD license on GitHub

Everything you really need to run it is in SoundOff_Binary.ZIP, which you can download independently. If you want the source, too, please feel free to clone the repository to your local git. If you do so, please take the time to read the README.md file before you try to use it.

查看更多
▲ chillily
5楼-- · 2020-02-03 05:24

What I use: VLC (free download) for Windows. Works from XP to 10.

use this

"c:\Program Files (x86)\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit 
"c:\Program Files (x86)\videolan\vlc\Windows Exclamation.wav"

Paths and quotes as example only; the meat is

vlc --qt-start-minimized --play-and-exit soundFilename
查看更多
ゆ 、 Hurt°
6楼-- · 2020-02-03 05:34
@echo off
set "file=track12.mp3"
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
  echo Sound.URL = "%file%"
  echo Sound.Controls.play
  echo do while Sound.currentmedia.duration = 0
  echo wscript.sleep 100
  echo loop
  echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs

just change track12.mp3 with the name of your audio file

查看更多
7楼-- · 2020-02-03 05:36

This is a copy/paste from another answer (also by me), that included this as a possible answer to one of the points (playing a wav file without a visible application) of the question.

For the play sound part, as far as i know, there is not way of directly playing a custom wav from command line without spawning another process. The usual tools are vlc, wmplayer, a vbs file instancing the wmplayer ocx, sound recorder, powershell, ... All this options are documented in previous questions (just the first) here in stackoverflow or here in superuser.

Expanding one of the alternatives, if you have access to some C compiler (tested with mingw) this code will generate a console tool that calls the PlaySound API function passing the first argument as the file to play.

#include <windows.h>
int main(int argc, char **argv)
{
    if (argc < 2) return 1;
    if (!PlaySound( 
            argv[1], 
            NULL, 
            SND_FILENAME | SND_NODEFAULT | SND_SYNC
       )
    ) return 2;
    return 0;
}

Depending of your configuration you will need to include a reference to the Winmm library to the linker.

查看更多
登录 后发表回答