Hello DOS folks,
I was wondering if there's a way in DOS (or Windows 7 in general) to play a media file without invoking a software.
Here's what I am looking for ... at the end of a batch file or a C++ program that takes many minutes to complete, I'd like to "beep" by playing the file "C:\Windows\Media\tada.wav".
I would like to use something like one of these commands, but don't want Windows to open whatever .WAV application. It's one more window to close.
start "" "C:\Windows\Media\tada.wav"
"C:\Windows\Media\tada.wav"
Just like with any other Windows notification (new mail or Windows error), I'd like my computer to just play the file without opening any application.
How could I achieve this?
Thank you,
--Steph
Play a sound (.wav) file, without opening an application
Moderator: DosItHelp
Re: Play a sound (.wav) file, without opening an application
There has to be an application involved which is able to process and play your sound file. But the Windows Media Player provides an interface without window using ActiveX. It's not accessible with Batch directly. But you can use hybrid scripts such as npocmaka's mediarunner.bat.
https://github.com/npocmaka/batch.scrip ... runner.bat
Steffen
https://github.com/npocmaka/batch.scrip ... runner.bat
Steffen
Re: Play a sound (.wav) file, without opening an application
You could ECHO BEL (0x07) (or many of them).
Saso
Saso
Re: Play a sound (.wav) file, without opening an application
Another predictable answer, but CmdWiz has the "playsound" operation. ( viewtopic.php?t=7402, see chapter 10).
You wrote that you don't want to invoke software, but the main thing seems to be avoiding a window opening ? Cmdwiz will not do that when run from a batch script.
You wrote that you don't want to invoke software, but the main thing seems to be avoiding a window opening ? Cmdwiz will not do that when run from a batch script.
Code: Select all
:: Play and wait for sound to finish
cmdwiz playsound C:\Windows\Media\tada.wav
:: Play without waiting
start /B cmdwiz playsound C:\Windows\Media\tada.wav
Re: Play a sound (.wav) file, without opening an application
If you're looking for anything other than a standard beep, you can embed VBScript inside your batch file. It uses an embedding method from dbenham over here https://stackoverflow.com/questions/907 ... ut-using-a. At the top of the script add
And at the bottom add
It contains 2 types of playing : repeating the mp3 after it is done over and over (Music) and just playing it once (Sound). You can make a macro called "music" for a handy way to access both.
Ie, if you want your tada.mp3 to play once, you can do:
Code: Select all
<!-- : Begin batch script
Code: Select all
----- Begin wsf script --->
<package>
<job id="Sound">
<script language="VBScript">
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = WScript.Arguments.Item(0)
Sound.Controls.play
do while Sound.currentmedia.duration = 0
Wscript.sleep 100
loop
Wscript.sleep (int(Sound.currentmedia.duration)+1)*1000
</script>
</job>
<job id="Music">
<script language="VBScript">
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = WScript.Arguments.Item(0)
Sound.settings.volume = 100
Sound.settings.setMode "loop", True
Sound.Controls.play
While Sound.playState <> 1
WScript.Sleep 100
Wend
</script>
</job>
</package>
Code: Select all
SET "music=START /B CSCRIPT //NOLOGO "%~f0?.wsf" //JOB:t s.mp3 >NUL"
Code: Select all
%music:t s=Sound tada%