Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: All in one Batch music system. Can be used to play songs or sound effects, only the main batch window is visible.
- ::: Requires write permission in the folder the program is run from.
- ::: This is a refinement of the system demonstrated in this game-in-progress: https://www.youtube.com/watch?v=DuzQ_lXwegg
- @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 directyly 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement