I am making a batch game in notepad and I was wondering how I can play the file music in the background.
I have this:
@echo off
start Music.mp3
Pause
What this does is it starts my music named Music.mp3 but it starts it in a separate window that pops up. What I want is for it to start playing, but not pop up in a window. I also want it to start and play in the background as I play my game.
Any ways I could do this?
The closest your can get using internal commands of a command processor can only minimize a window. If you really want to "background" it, the script will be long and confusing.
start /min /c "" Music.mp3
Alternatively this:
@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
cscript.exe //nologo sound.vbs
This creates a vbs that starts the music without a new window.
User Lưu Vĩnh Phúc has suggested, using a hybrid script prevents the issue of cleaning up.
@echo off
rem ----START OF BATCH CODE---
rem You can paste your entire batch code down here, and use
rem the cscript command whenever you want to play the sound.
cscript //nologo "%~f0?.wsf" //job:VBS
rem ----END OF BATCH CODE---
<package>
<job id="JS">
<script language="VBScript">
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "%file%"
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep (int(Sound.currentmedia.duration)+1)*1000)
</script>
</job>
Here's another script based on WMPlayer.OCX.You can use it like:
mediarunner.bat Music.mp3
Here's one based on the bgsound tag in internet explorer.It allows you also to set sound volume as parameter.Does not require installed media player unlike WMPlayer.OCX approach:
soundPlayer.bat Music.mp3 -50
One based on SP objects though unfortunately it can play only wav files:
spplayer.bat file.wav
None of the script creates temp files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With