Advertisement
T3RRYT3RR0R

Batch Music and SFX player

Apr 21st, 2020
2,381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.63 KB | None | 0 0
  1. ::: All in one Batch music system. Can be used to play songs or sound effects, only the main batch window is visible.
  2. ::: Requires write permission in the folder the program is run from.
  3. ::: This is a refinement of the system demonstrated in this game-in-progress: https://www.youtube.com/watch?v=DuzQ_lXwegg
  4.  
  5. @ECHO OFF & CD "%~dp0"
  6.     Set "ProgDir=%~dp0"
  7.     If not exist "%ProgDir%Sounds" MD "%ProgDir%Sounds"
  8.     Set "Sounds=%ProgDir%Sounds"
  9.     Set "Player=%Sounds%\BatchMusicPlayer.bat"
  10.     Set "MusicStopper=%Sounds%\StopMusic.bat"
  11.     Set "Monitor=%Sounds%\BatchMonitor.vbs"
  12.     If not Exist "%Player%" Call :makeplayer
  13.     If not Exist "%MusicStopper%" Call :makestopper
  14.     If not Exist "%Monitor%" Call :makemonitor
  15.  
  16. Start "" "%Monitor%"
  17.  
  18. :main
  19. REM play directyly by calling this batch using these parameters: <full track path> <vol 0-100> <Loop true / false>
  20.     If not "%~3"=="" If Exist "%~1" (
  21.         For %%A in (true false) do If /I "%%A" == "%~3" (
  22.             Call "%Player%" "%~1" %~2 %~3
  23.             Exit /B
  24.         )
  25.     )
  26. REM autoplay any song or sound dropped on the batch or when called without additional parameters.
  27.     If Exist "%~1" If "%~2"=="" (Set "track=%~1" & Set "vol=80" & Set "Loop_TF=false" & Goto :Launch)
  28.  
  29. REM manually enter trackpath, volume and true / false value for repeating sound.       
  30.        
  31.     )  
  32.     cls
  33.     Set track=
  34.     Set /p "track=[Full track path :>"
  35.     IF NOT DEFINED track Goto :main
  36.     For %%A in (quit q exit e killmusic stop) do IF /I "%track%" == "%%A" Goto :end
  37.     IF /I NOT EXIST "%track%" Goto :main
  38.  
  39. :volume
  40.     set vol=
  41.     Set /p "vol=[Volume :>"
  42.     For %%A in ("%vol%") do (
  43.         For %%B in (q quit e exit c cancel s stop) do IF /I "%%~A" == "%%B" Goto :main
  44.         For /L %%C in (1,1,100) do If "%%~A"=="%%C" Goto :repeat
  45.     )
  46. Goto :volume
  47.  
  48. :repeat
  49.     Set Loop_TF=
  50.     Set /p "Loop_TF=[Repeat ('true' or 'false') :>"
  51.     IF NOT DEFINED Loop_TF Goto repeat
  52.     For %%A in ("%Loop_TF%") do (
  53.         For %%B in (true false) do IF /I "%%~A" == "%%B" Goto :Launch
  54.         For %%C in (q quit e exit c cancel s stop) do IF /I "%%~A" == "%%C" Goto :main
  55.     )
  56. Goto :repeat
  57.  
  58. :Launch
  59.     CALL "%player%" "%track%" %vol% %Loop_TF%
  60. REM Exit /B
  61.     pause
  62. Goto :main
  63.  
  64. :makeplayer
  65. (
  66.     Echo.@ECHO OFF
  67.     Echo.Set "MusicPath=%%~1"
  68.     Echo.Set "vol=%%~2"
  69.     Echo.Set "Loop_TF=%%~3"
  70. REM Change to the Directory you want to create the Music Launcher in.
  71.     Echo.PUSHD %%sounds%%
  72. REM Ensure no Conflict with the Previous Script.
  73.     Echo.IF exist PlayMusic.vbs ^(
  74.     Echo.DEL PlayMusic.vbs
  75.     Echo.^)
  76. REM Creates a vbs Script to Launch the music (Occurs without any visual indication or prompting)
  77.     Echo.^( echo Set Sound = CreateObject^("WMPlayer.OCX.7"^^^)
  78.     Echo.echo Sound.URL = "%%MusicPath%%"
  79.     Echo.echo Sound.settings.volume = %%vol%%
  80.     Echo.echo Sound.settings.setMode "loop", %%Loop_TF%%
  81.     Echo.echo Sound.Controls.play
  82.     Echo.echo While Sound.playState ^^^<^^^> 1
  83.     Echo.echo      WScript.Sleep 100
  84.     Echo.echo Wend
  85.     Echo.^)^>PlayMusic.vbs
  86.     Echo.start /min PlayMusic.vbs
  87. ::: Return to the Previous Directory
  88.     Echo.POPD
  89. ::: Exit the Launcher and return to Previous batch program.
  90.     Echo.Goto :EOF
  91. )>%Player%
  92. Exit /B
  93.  
  94. :makemonitor
  95. (
  96. ECHO Set objWMIService = GetObject ("winmgmts:"^)
  97. ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
  98. ECHO DO while proc.count ^> 0
  99. ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
  100. ECHO if proc.count ^< 1 then exit do
  101. ECHO wscript.sleep 1500
  102. ECHO loop
  103. ECHO Set WshShell=createobject("wscript.shell"^)
  104. ECHO WshShell.run "%MusicStopper%", 0, true
  105. )>"%Monitor%"
  106. Exit /B
  107.  
  108. :makestopper
  109. (
  110. Echo.@ECHO OFF
  111. Echo.taskkill /pid WScript.exe /f /t ^>nul
  112. Echo.Goto :EOF
  113. )>%MusicStopper%
  114. Exit /B
  115.  
  116. :end
  117. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement