Question

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?

Was it helpful?

Solution

@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

To loop the same song:

@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

:loop
start "" /wait /min sound.vbs
goto:loop

OTHER TIPS

CreateObject("Wscript.Shell").Run "wmplayer /play /close ""Your file location here""", 0, False

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.

Batch Music Player.bat

@echo off
setlocal enabledelayedexpansion
Set vbsfile=%temp%\Intro.vbs
Set URL=http://hackoo.alwaysdata.net/Intro_DJ.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
Set MyFile=%~f0
Set ShorcutName=DJ Batch Music Player
(
echo Call Shortcut("%MyFile%","%ShorcutName%"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo    Dim objShell,DesktopPath,objShortCut,MyTab
echo    Set objShell = CreateObject("WScript.Shell"^)
echo    MyTab = Split(CheminApplication,"\"^)
echo    If Nom = "" Then
echo    Nom = MyTab(UBound(MyTab^)^)
echo    End if
echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo    objShortCut.TargetPath = Dblquote(CheminApplication^)
echo    ObjShortCut.IconLocation = "Winver.exe,0"
echo    objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo    DblQuote = Chr(34^) ^& Str ^& Chr(34^)
echo End Function
echo ^'**********************************************************************************************
) > %temp%\Shortcutme.vbs
Start /Wait %temp%\Shortcutme.vbs
Del %temp%\Shortcutme.vbs
::****************************************************************************************************
Title DJ Batch Music Player by Hackoo 2015
:menuLOOP
Color 0A & Mode con cols=78 lines=25
echo(
echo        ===============================================================
echo        "/  |  /  |                    /  |                          ";
echo        "$$ |  $$ |  ______    _______ $$ |   __   ______    ______  ";
echo        "$$ |__$$ | /      \  /       |$$ |  /  | /      \  /      \ ";
echo        "$$    $$ | $$$$$$  |/$$$$$$$/ $$ |_/$$/ /$$$$$$  |/$$$$$$  |";
echo        "$$$$$$$$ | /    $$ |$$ |      $$   $$<  $$ |  $$ |$$ |  $$ |";
echo        "$$ |  $$ |/$$$$$$$ |$$ \_____ $$$$$$  \ $$ \__$$ |$$ \__$$ |";
echo        "$$ |  $$ |$$    $$ |$$       |$$ | $$  |$$    $$/ $$    $$/ ";
echo        "$$/   $$/  $$$$$$$/  $$$$$$$/ $$/   $$/  $$$$$$/   $$$$$$/  ";
echo        "                                                            ";
echo        "                                                            ";
echo(       =============================Menu==============================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo                         %%A  %%B
echo(
echo(       ===============================================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::********************************************************************************************
:menu_[1] Play DJ Buzz Radio
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching DJ Buzz Radio ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\DJBuzzRadio.vbs
Set URL=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[2] Play David Guetta Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching David Guetta Mix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\David_Guetta_Miami.vbs
Set URL=http://hackoo.alwaysdata.net/David_Guetta_Miami_2014.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[3] Play Ibiza Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Ibiza Mix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL=http://hackoo.alwaysdata.net/IbizaMix.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[4] Play Avicii Mega Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Avicii Megamix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL="http://hackoo.alwaysdata.net/Best of Avicii Megamix 2014.mp3"
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[5] Play Mega Mix 90
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Mega Mix 90 ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL="http://hackoo.alwaysdata.net/Megamix 90.mp3"
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[6] Stop the music
cls & color 0C
Call:SkipLine 10
Call:Tab 3
echo  %x% Please Wait for a while .. Stopping the music ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo    Dim Sound
echo    Set Sound = CreateObject("WMPlayer.OCX"^)
echo    Sound.URL = URL
echo    Sound.settings.volume = 100
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
echo End Sub
)>%~2
::*********************************************************************************************
:Tab
set "x="
For /L %%I In (1,1,%1) Do Set "x=!x!    "
REM                                  ^-- this is a TAB
goto :eof
::*********************************************************************************************
:SkipLine
    For /L %%I In (1,1,%1) Do Echo(
    Goto:Eof
:EOF
EXIT
::********************************************************************************************* 

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.

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

Just use Sounder.exe

example your command line would be Sounder MyWaveFile.wav

Get it from

http://www.elifulkerson.com/projects/commandline-wav-player.php

This is an all in one solution for playing sound files in a batch program while keeping everything hidden, with the innate capacity to stop the music when the cmd window is closed. Utilizes vbs scripts and secondary batch programs, each created from the initial script.

It uses similar approaches to other answers regarding the use of vbs to play music with controlled settings.

@ECHO OFF & CD "%~dp0"
    Set "ProgDir=%~dp0"
    If not exist "%ProgDir%Sounds" MD "%ProgDir%Sounds"
    Set "Sounds=%ProgDir%Sounds"
    Set "Player=%Sounds%\BatchMusicPlayer.bat"
    Set "MusicStopper=%Sounds%\StopMusic.bat"
    Set "Monitor=%Sounds%\BatchMonitor.vbs"
    If not Exist "%Player%" Call :makeplayer
    If not Exist "%MusicStopper%" Call :makestopper
    If not Exist "%Monitor%" Call :makemonitor

Start "" "%Monitor%"

:main
REM play directly by calling this batch using these parameters: <full track path> <vol 0-100> <Loop true / false>
    If not "%~3"=="" If Exist "%~1" (
        For %%A in (true false) do If /I "%%A" == "%~3" (
            Call "%Player%" "%~1" %~2 %~3
            Exit /B
        )
    )
REM autoplay any song or sound dropped on the batch or when called without additional parameters.
    If Exist "%~1" If "%~2"=="" (Set "track=%~1" & Set "vol=80" & Set "Loop_TF=false" & Goto :Launch)

REM manually enter trackpath, volume and true / false value for repeating sound.        

    )   
    cls
    Set track=
    Set /p "track=[Full track path :>"
    IF NOT DEFINED track Goto :main
    For %%A in (quit q exit e killmusic stop) do IF /I "%track%" == "%%A" Goto :end
    IF /I NOT EXIST "%track%" Goto :main

:volume
    set vol=
    Set /p "vol=[Volume :>"
    For %%A in ("%vol%") do (
        For %%B in (q quit e exit c cancel s stop) do IF /I "%%~A" == "%%B" Goto :main
        For /L %%C in (1,1,100) do If "%%~A"=="%%C" Goto :repeat
    )
Goto :volume

:repeat
    Set Loop_TF=
    Set /p "Loop_TF=[Repeat ('true' or 'false') :>"
    IF NOT DEFINED Loop_TF Goto repeat
    For %%A in ("%Loop_TF%") do (
        For %%B in (true false) do IF /I "%%~A" == "%%B" Goto :Launch
        For %%C in (q quit e exit c cancel s stop) do IF /I "%%~A" == "%%C" Goto :main
    )
Goto :repeat

:Launch
    CALL "%player%" "%track%" %vol% %Loop_TF%
REM Exit /B
    pause
Goto :main

:makeplayer
(
    Echo.@ECHO OFF
    Echo.Set "MusicPath=%%~1"
    Echo.Set "vol=%%~2"
    Echo.Set "Loop_TF=%%~3"
REM Change to the Directory you want to create the Music Launcher in.
    Echo.PUSHD %%sounds%%
REM Ensure no Conflict with the Previous Script.
    Echo.IF exist PlayMusic.vbs ^(
    Echo.DEL PlayMusic.vbs
    Echo.^)
REM Creates a vbs Script to Launch the music (Occurs without any visual indication or prompting)
    Echo.^( echo Set Sound = CreateObject^("WMPlayer.OCX.7"^^^)
    Echo.echo Sound.URL = "%%MusicPath%%"
    Echo.echo Sound.settings.volume = %%vol%%
    Echo.echo Sound.settings.setMode "loop", %%Loop_TF%%
    Echo.echo Sound.Controls.play
    Echo.echo While Sound.playState ^^^<^^^> 1
    Echo.echo      WScript.Sleep 100
    Echo.echo Wend
    Echo.^)^>PlayMusic.vbs
    Echo.start /min PlayMusic.vbs
::: Return to the Previous Directory
    Echo.POPD
::: Exit the Launcher and return to Previous batch program.
    Echo.Goto :EOF
)>%Player%
Exit /B

:makemonitor
(
ECHO Set objWMIService = GetObject ("winmgmts:"^)
ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
ECHO DO while proc.count ^> 0
ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
ECHO if proc.count ^< 1 then exit do
ECHO wscript.sleep 1500
ECHO loop
ECHO Set WshShell=createobject("wscript.shell"^)
ECHO WshShell.run "%MusicStopper%", 0, true
)>"%Monitor%"
Exit /B

:makestopper
(
Echo.@ECHO OFF
Echo.taskkill /pid WScript.exe /f /t ^>nul
Echo.Goto :EOF
)>%MusicStopper%
Exit /B

:end
exit

If you can use a third-party utility then wv_player is a free media player that has a simple gui and has command line switches to play media files with no interface.

Most suggested is MediaPlayer or the relative ActiveX object . This could be problem for a people without installed MediaPlayer (e.g. Windows XP required genuine authentication in order to install it) and it can acts differently on different windows versions (e.g. on some windows version auto closing does not work as expected). Here's my implementation (does not create temporary files).Example:

call mediaRunner.bat "C:\Windows\Media\Ring05.wav"

On every windows machine there are installed SP ActiveX objects which are capable to run .wav files (no mp3 and so on). Here's one script.Expample:

call spPlayer.bat "C:\Windows\Media\Ring05.wav"

and we have also HTA/InternetExplorer applications and their bgsound tag.Which also allows you to control the volume of the played song:

call htaplayer.bat "C:\Windows\Media\Ring05.wav" -1000

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.

If someone need turn off music and play another.
Try this:

Taskkill /IM "wscript.exe" /F>nul 2>&1

(If you use sound.vbs)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top