I am creating a batch file and I would like to have a .wav file to play on command in the background when I am running the batch file in command prompt. I would like to have it so no other app is opened to play the file and for it to play right out of command prompt. Is there any possible solution to this? Thanks.
Asked
Active
Viewed 1,600 times
1
-
1This is not technically supported by cmd. But you can use other technology built into Windows to kinda hack it. http://stackoverflow.com/questions/23313709/play-invisible-music-with-batch-file – soja Oct 02 '16 at 06:43
-
Possible duplicate of [Batch File To Play A Song](http://stackoverflow.com/questions/20418730/batch-file-to-play-a-song) – SachaDee Oct 03 '16 at 19:58
2 Answers
1
You can try something like that :
You can change the variable sound to your .wav
path
For example you can set like this : Set "sound=C:\windows\Media\tada.wav"
@echo off
Mode con cols=50 lines=3
Title Playing DJ Buzz Radio by Hackoo
:Play DJ Buzz Radio
cls & color 0A
echo(
Set "Sound=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx"
Rem Set "Sound=C:\windows\Media\tada.wav"
echo Playing Now DJ Buzz Radio ...
Call :Play "%Sound%"
::*******************************************************
:Play <sound>
set "_vbs=%tmp%\%~n0.vbs"
(
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
)>"%_vbs%"
cscript /nologo "%_vbs%"
::*******************************************************

Hackoo
- 18,337
- 3
- 40
- 70
0
This worked very well for me. All you have to do is change C:\Windows\Media\Windows Critical Stop.wav to whatever your file name is.
@echo off
title ERROR
::"setting up" error sound - creating vbs file to make sound
set "file=C:\Windows\Media\Windows Critical Stop.wav"
( 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
::playing sound
start /min sound.vbs
::wait 1 second for vbs to let go of file
ping n- 1 127.0.0.1>nul
::delete vbs file
del sound.vbs

Michael K-F
- 1
- 1