Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: All programs Designed by T3RRYG00D Games.
- ::: This Guide Covers All the Programs Necessary to Make a Batch / Vbs Hybrid Music Player which
- ::: offers Independent User control over Volume settings for both songs and sound effects, Control of Music Flow, and
- ::: a means by which to automatically stop the music - However the batch gets closed.
- :::
- ::: The player does not appear To the user, nor do the batch programs that control it.
- ::: The Player utilizes Windows Media Player, and can play any sound file Compatible with W.M.P.
- ::: This Guide does not detail how to change volume setting, but it's just a case of choosing a method of input
- ::: for the player to select the volume they desire, then saving that setting to the file used by the program
- ::: in the same format initially used to store the settings.
- ::: Preperations to make in your Games Launcher:
- ::: In your Games Launcher (GameName.bat), Which should be in the Top level of the Games Directory (Folder) Set "GameDir=%~dp0"
- ::: %~dp0 is the fully qualified filepath for the folder your games in. Example- C:\Users\Username\desktop\Gamename\
- ::: %~dp0 expands for the batch program currently in effect. It's assigned to a variable, as it will change when another batch is in use.
- ::: This will define the relative path for all other files and programs in your games folder, Irregardless of where the folder is located.
- ::: Other Filepaths to Define in your Games starting Program (With regards to Sound):
- ::: 'sounds' should be a subfolder in your Games Folder
- ::: Set "sounds=%GameDir%sounds"
- ::: These are small Programs and files to handle Different aspects of controlling Music.
- ::: Set "MusicSettings=%sounds%\MusicSettings.txt"
- ::: Set "AutoStop=%sounds%\AutoStop.bat
- ::: Set "StartMusic=%sounds%\StartMusic.bat
- ::: Set "StopMusic=%sounds%\StopMusic.bat
- ::: Set "ChangeSong=%sounds%\ChangeSong.bat
- ::: ******************************* Default Settings *******************************
- ::: Before Playing Music, you need to define your default settings as variables.
- ::: The 'IF not exist' check will ensure player selected settings are not overriden.
- ::: The first number is used to check if Music is enabled. 1 is on, 0 is off.
- ::: The second number is used to check if Sound effects are enabled. 1 is on, 0 is off.
- ::: The third number is the Music Volume
- ::: The fourth number is the Sound Effect Volume
- IF not exist "%Musicsettings%" (
- ECHO 1
- ECHO 1
- ECHO 50
- ECHO 30
- )>%Musicsettings%
- ::: Immediately after Settings are created, they need to be assigned to variables.
- <"%MusicSettings%" (
- Set /p MusicOI=
- Set /p SEffectsOI=
- Set /p MusicVolume=
- Set /p SEffectsVolume=
- )
- ::: Implements Disabled sound settings without Permanently changing stored Volume Settings.
- IF %MusicOI%==0 Set "MusicVolume=0"
- IF %SEffectsOI%==0 Set "SEffectsVolume=0"
- ::: *End Assignment of Sound Settings*
- ::: Before Starting your Music, you want to put in place a way to close it Even if
- ::: the player closes the console. To do this, you can use a VBS script to monitor
- ::: for when cmd.exe gets closed. Once the game is closed, it will call a program
- ::: to end the music.
- ::: ********************************* AutoStop.bat *********************************
- ::: Should be Called early in your launcher, after filepaths are set.
- @ECHO OFF
- ::: Creates a VBS script to monitor the Games Process
- (
- ECHO Set objWMIService = GetObject ("winmgmts:"^) 'Defines winmgmts service
- ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^) 'Gets Current Process Count
- ECHO DO while proc.count ^> 0 'Establishes Loop that ends when no cmd.exe windows or bat programs are open
- ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^) 'Gets Current Process Count
- ECHO if proc.count ^< 1 then exit do 'exits while loop once bat program is closed
- ECHO wscript.sleep 2500 'Delays loop by 2.5 seconds to reduce CPU usage
- ECHO loop 'Returns to get new process Count
- ECHO Set WshShell=createobject("wscript.shell"^) 'Creates Shell to
- ECHO WshShell.run "%GameDir%sounds\StopMusic.bat", 0, false 'Launches hidden .bat to close vbs player using TASKKILL once Game is closed
- ECHO WshShell.run "%~0", 0, false 'launches the program in hidden state to restart this vbs script. Does not occur if Game is closed.
- ) >%GameDir%sounds\MonitorEXE.vbs
- ::: Starts the VBS to monitor if game is open
- Start %GameDir%sounds\MonitorEXE.vbs
- ::: Used to Identify to Stop Music that AutoStop Needs to be Called when Changing Songs.
- ::: When Changing Songs, Use ChangeSong.bat
- Set "Monitoring=0"
- ::: optional notification to user that Autostop is active.
- ::: mshta vbscript:msgbox("Autostop Active",0,"Your Games Name as Title")(window.close)
- GOTO :EOF
- ::: ********** End of Autostop.bat Program. **********
- ::: To begin playing music, call your StartMusic.bat program.
- ::: StartMusic.bat NEEDS to be called the first time a SONG is played in your Batch
- ::: this is due to ChangeSong Calling StopMusic. If there's no music being played,
- ::: An error message will occur when StopMusic tries to... Stop the Music.
- ::: *StartMusic.bat* MUST be used for Sound Effects.
- ::: Your call uses three parameters, which you change depending whether your Starting a song
- ::: or Playing a Sound effect. The 1st parameter is the filename of your song, the 2nd is the volume
- ::: and the third is whether Looping is true or false.
- ::: For songs, you want to use true, For Sound effects, use false
- :::
- ::: Your Songs and Sound Effects need to be located in your sounds folder. This allows you to
- ::: Make the calls demonstrated below with Just the Filename and extension - No Filepath Required.
- ::: To start a Song (Only for the First time your program starts a song):
- CALL "%StartMusic%" filename.ext %MusicVolume% true
- ::: To play a Sound Effect:
- CALL "%StartMusic%" filename.ext %SEffectsVolume% false
- ::: ******************************** StartMusic.bat ********************************
- @ECHO OFF
- ::: Change to the Directory you want to create the Music Launcher in.
- ::: Being in the same Directory your sound file in is what allows you to make the calls
- ::: with just the filename and extension as previously mentioned.
- PUSHD %sounds%
- ::: Ensure no Conflict with the Previous Script.
- IF exist PlayMusic.vbs (
- DEL PlayMusic.vbs
- )
- ::: Creates a vbs Script to launch the music (Occurs without any visual indication or prompting)
- (
- echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
- echo Sound.URL = "%~1"
- echo Sound.settings.volume = %~2
- echo Sound.settings.setMode "loop", %~3
- echo Sound.Controls.play
- echo While Sound.playState ^<^> 1
- echo WScript.Sleep 100
- echo Wend
- )>PlayMusic.vbs
- start /min PlayMusic.vbs
- ::: Return to the Previous Directory
- POPD
- ::: Exits StartMusic and returns to the Previous program.
- GOTO :EOF
- ::: ********** End of StartMusic.bat Program. **********
- ::: ChangeSong MUST NOT be used to play sound effects, as doing so will Stop songs.
- ::: For ALL times APART FROM the STARTING SONG you want to change SONGS, You MUST Call ChangeSong.
- :::
- ::: Your call uses three parameters, which you change depending whether your Starting a song
- ::: or Playing a Sound effect. The 1st parameter is the filename of your song, the 2nd is the volume
- ::: and the third is whether Looping is true or false.
- ::: For songs, you want to use true.
- ::: To Change Song:
- CALL "%ChangeSong%" filename.ext %MusicVolume% true
- ::: ******************************* ChangeSong.bat ********************************
- @ECHO OFF
- ::: The Monitoring Variable is used to Convey to StopMusic that it needs to restart
- ::: the AutoStop.bat, as it gets closed with the musicplayer. AutoStop resets the
- ::: variable to 0, preventing a loop from occuring.
- Set "Monitoring=1"
- CALL %StopMusic%
- ::: Forward the settings to StartMusic.Bat
- CALL %StartMusic% %~1 %~2 %~3
- GOTO :EOF
- ::: ********** End of ChangeSong.bat Program. ***********
- ::: ********************************* StopMusic.bat ********************************
- @ECHO OFF
- ::: Stops the vbs.script controlling Windows Media Player - As well as the AutoStop Monitor.
- taskkill /pid WScript.exe /f /t >nul
- ::: Delay required to allow time for TASKKILL to complete execution before restarting Autostop
- ::: failure to implement a delay will restart in AutoStop being wiped out By TASKKILL
- Timeout 1 > nul
- ::: Restarts the Autostop Monitor If game is Still active. This is why monitoring is Set to 0 in AutoStop.bat
- IF %Monitoring%==1 CALL "%AutoStop%"
- ::: Exits the StopMusic and returns to the Previous program if Game is still active.
- GOTO :EOF
- ::: ********** End of StopMusic Program. ***********
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement