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
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---