Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#1
Post
by grotch » 31 Jul 2016 07:37
Hello,
I want to create a soundboard with batch,
but I have a problem:
When I run the batchfile it does not start the soundfile.
Code: Select all
@echo off
if not exist "C:\Users\%username%\Music\Soundboard" md "C:\Users\%username%\Music\Soundboard"
set sounds_path=C:\Users\%username%\Music\Soundboard\
set sound1=yey.mp3
set sound2=9_mm_gunshot.mp3
set sound3=Audience_Applause.mp3
set sound4=Demon_Your_Soul_is_mine.mp3
set sound5=Evil_Laugh_1.mp3
set sound6=Helicopter_Approach.mp3
set sound7=MP5_SMG.mp3
set sound8=RPG_Plus_Shrapnel.mp3
set sound9=Winchester12.mp3
::selecting sound
:selecting
cls
echo Choose a sound from the list below by pressing its button.
echo.
echo 1. Yey
echo 2. 9 mm gunshot
echo 3. Audience Applause
echo 4. Your soul is mine
echo 5. Evil Laugh
echo 6. Helicopter
echo 7. MP5 SMG
echo 8. RPG Plus Shrapnel
echo 9. Winchester
set /p selected_sound=
::refer and play sound
if selected_sound==1 (
start /min %sounds_path%%sound1%
goto after_play
)
if selected_sound==2 (
start /min %sounds_path%%sound2%
goto after_play
)
if selected_sound==3 (
start /min %sounds_path%%sound3%
goto after_play
)
if selected_sound==4 (
start /min %sounds_path%%sound4%
goto after_play
)
if selected_sound==5 (
start /min %sounds_path%%sound5%
goto after_play
)
if selected_sound==6 (
start /min %sounds_path%%sound6%
goto after_play
)
if selected_sound==7 (
start /min %sounds_path%%sound7%
goto after_play
)
if selected_sound==8 (
start /min %sounds_path%%sound8%
goto after_play
)
if selected_sound==9 (
start /min %sounds_path%%sound9%
goto after_play
)
::stopping the sound player
:after_play
ping >NUL 1
pause
goto selecting
I hope you dont get confused with the uncomplete code and maybe some dumb mistakes.
Also why does "start /min " only work with batchfiles and not other programms.
Thanks for reading
grotch
-
aGerman
- Expert
- Posts: 4742
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 31 Jul 2016 08:12
The START command doesn't wait that the sound file has been finished. If .mp3 is not associated with a certain player nothing will even happen.
START /MIN does work for applications but you try to run a file without directly running an application (player). You have to specify the path to your player and pass the soundfile to it. E.g.
Code: Select all
start "" /min "C:\path to\player.exe" "%sounds_path%%sound1%"
If your player has an option in order to automatically quit after playing the sound file you have to pass it too.
Regards
aGerman
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#3
Post
by grotch » 31 Jul 2016 12:14
aGerman wrote:The START command doesn't wait that the sound file has been finished. If .mp3 is not associated with a certain player nothing will even happen.
START /MIN does work for applications but you try to run a file without directly running an application (player). You have to specify the path to your player and pass the soundfile to it. E.g.
Code: Select all
start "" /min "C:\path to\player.exe" "%sounds_path%%sound1%"
If your player has an option in order to automatically quit after playing the sound file you have to pass it too.
Regards
aGerman
Thanks for your answer.
My player is VLC Media player, but I want it to work for media player too.
I have changed it to your command, but it still does not work for my programm.
I have run this command in cmd.exe and it does work in there.
Code: Select all
::refer and play sound
if selected_sound==1 (
start "" /min "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "%sounds_path%%sound1%"
goto after_play
)
-
aGerman
- Expert
- Posts: 4742
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 31 Jul 2016 12:51
You missed the percent signs around your variable
Regards
aGerman
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#5
Post
by grotch » 31 Jul 2016 12:57
aGerman wrote:You missed the percent signs around your variable
Regards
aGerman
Thanks, I missed that the hole time.
Now it works, except that /min doesnt seem to work.
grotch
-
aGerman
- Expert
- Posts: 4742
- Joined: 22 Jan 2010 18:01
- Location: Germany
#6
Post
by aGerman » 31 Jul 2016 13:10
I just read the
VLC command-line help.
Untested:
Code: Select all
start "" "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "%sounds_path%%sound1%" --qt-start-minimized --play-and-exit
Regards
aGerman
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#7
Post
by grotch » 31 Jul 2016 13:52
aGerman wrote:I just read the
VLC command-line help.
Untested:
Code: Select all
start "" "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "%sounds_path%%sound1%" --qt-start-minimized --play-and-exit
Regards
aGerman
Thanks so much,
it works.
I looked for windows media player parameters and found out that it does not support any of the above features,
so I am probably going to make to different versions: one for vlc player and one for wm player.
grotch
-
aGerman
- Expert
- Posts: 4742
- Joined: 22 Jan 2010 18:01
- Location: Germany
#8
Post
by aGerman » 31 Jul 2016 14:19
You're wellcome!
so I am probably going to make to different versions: one for vlc player and one for wm player.
As far as I know the WMPlayer doesn't even support to quit running after playing a certain file. Thus, you should better stuck with VLC.
Regards
aGerman
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#9
Post
by grotch » 04 Aug 2016 08:50
Now I have another problem.
I want to make an installer for my program,
but it keeps closing right when I start it.
I have the soundboard installed already,
so it probably has a problem with the reinstall and uninstall part.
Code: Select all
@echo off
:start
if not exist "C:\Users\%username%\Documents\Soundboard" (
cls
md "C:\Users\%username%\Documents\Soundboard"
copy "Soundboard.bat" "C:\Users\%username%\Documents\Soundboard"
copy "Soundboard_settings.bat" "C:\Users\%username%\Documents\Soundboard"
cd "C:\Users\%username%\Desktop"
mklink "Batch Soundboard" "C:\Users\%username%\Documents\Soundboard\Soundboard.bat"
goto :eof
) else (
cls
echo The Batch Soundboard is already installed on your computer.
echo Type "r" to reinstall or "u" to uninstall.
set /p re_un=
if %re_un%==r (
rd /s /q "C:\Users\%username%\Documents\Soundboard"
call start
echo Sucessfully reinstalled Batch Soundboard.
echo.
echo.
)
cls
if %re_un%==u (
rd /s /q "C:\Users\%username%\Documents\Soundboard"
echo Sucessfully uninstalled Batch Soundboard.
echo.
echo.
)
pause
goto :eof
)
Also should I make another thread for this?
grotch
-
aGerman
- Expert
- Posts: 4742
- Joined: 22 Jan 2010 18:01
- Location: Germany
#10
Post
by aGerman » 04 Aug 2016 11:42
Untested:
Code: Select all
@echo off
if not exist "%userprofile%\Documents\Soundboard" (
md "%userprofile%\Documents\Soundboard"
call :install
exit /b
)
echo The Batch Soundboard is already installed on your computer.
choice /c ru /n /m "Type \"r\" to reinstall or \"u\" to uninstall: "
if errorlevel 2 (
rd /s /q "%userprofile%\Documents\Soundboard"
echo Sucessfully uninstalled Batch Soundboard.
pause
exit /b
)
call :install
echo Sucessfully reinstalled Batch Soundboard.
pause
exit /b
:install
copy /y "Soundboard.bat" "%userprofile%\Documents\Soundboard"
copy /y "Soundboard_settings.bat" "%userprofile%\Documents\Soundboard"
pushd "%userprofile%\Desktop"
mklink "Batch Soundboard" "%userprofile%\Documents\Soundboard\Soundboard.bat"
popd
exit /b
Regards
aGerman
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#11
Post
by grotch » 04 Aug 2016 13:00
Thanks, Im going to test that tomorrow.
grotch
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#12
Post
by foxidrive » 04 Aug 2016 17:41
grotch wrote:Also should I make another thread for this?
No, this is a good place to continue talking about your script.
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#13
Post
by grotch » 05 Aug 2016 09:06
Thanks, it works.
Why did you use pushd and popd(I dont understand what they do)?
foxidrive wrote:No, this is a good place to continue talking about your script.
Thanks for the answer.
grotch
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#14
Post
by Squashman » 05 Aug 2016 09:20
grotch wrote:Why did you use pushd and popd(I dont understand what they do)?
Code: Select all
H:\>pushd /?
Stores the current directory for use by the POPD command, then
changes to the specified directory.
H:\>popd /?
Changes to the directory stored by the PUSHD command.
-
grotch
- Posts: 12
- Joined: 31 Jul 2016 07:12
#15
Post
by grotch » 05 Aug 2016 09:26
Squashman wrote:grotch wrote:Why did you use pushd and popd(I dont understand what they do)?
Code: Select all
H:\>pushd /?
Stores the current directory for use by the POPD command, then
changes to the specified directory.
H:\>popd /?
Changes to the directory stored by the PUSHD command.
Thanks for the answer,
I read that myself and didnt understand it.
But after thinking a bit more about it I now do.
grotch