批量发声?
Sound in batch?
我正在批量制作游戏,我想在玩家'battling'时播放音乐。我设法播放了音乐,但是当玩家完成战斗后我似乎无法停止音乐。
@echo off
set "file=BattleMusic.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
start /min sound.vbs'
那是我的音乐剧本。关于播放器完成后如何停止它的任何想法?
@echo off
set "file=BattleMusic.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
start /min sound.vbs
for /f "tokens=2" %%i in ('tasklist ^|find "wscript.exe"') do set pid=%%i
echo press any key to stop the sound
pause >nul
taskkill /f /pid %pid%
当然这可能会有问题,如果另一个 wscript.exe
是 运行。但是您可以在启动您的之前保存他们的 PID,并且仅停止 "the new one".
您必须终止进程 wscript.exe
看看这个带有动态菜单的例子,其中有一个停止音乐的选项:
@echo off
setlocal enabledelayedexpansion
Set vbsfile=%temp%\Intro.vbs
Set URL=http://hackoo.alwaysdata.net/Intro_DJ.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
Set MyFile=%~f0
Set ShorcutName=DJ Batch Music Player
(
echo Call Shortcut("%MyFile%","%ShorcutName%"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo Dim objShell,DesktopPath,objShortCut,MyTab
echo Set objShell = CreateObject("WScript.Shell"^)
echo MyTab = Split(CheminApplication,"\"^)
echo If Nom = "" Then
echo Nom = MyTab(UBound(MyTab^)^)
echo End if
echo DesktopPath = objShell.SpecialFolders("Desktop"^)
echo Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo objShortCut.TargetPath = Dblquote(CheminApplication^)
echo ObjShortCut.IconLocation = "Winver.exe,0"
echo objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo DblQuote = Chr(34^) ^& Str ^& Chr(34^)
echo End Function
echo ^'**********************************************************************************************
) > %temp%\Shortcutme.vbs
Start /Wait %temp%\Shortcutme.vbs
Del %temp%\Shortcutme.vbs
::****************************************************************************************************
Title DJ Batch Music Player by Hackoo 2015
:menuLOOP
Color 0A & Mode con cols=78 lines=25
echo(
echo ===============================================================
echo "/ | / | / | ";
echo "$$ | $$ | ______ _______ $$ | __ ______ ______ ";
echo "$$ |__$$ | / \ / |$$ | / | / \ / \ ";
echo "$$ $$ | $$$$$$ |/$$$$$$$/ $$ |_/$$/ /$$$$$$ |/$$$$$$ |";
echo "$$$$$$$$ | / $$ |$$ | $$ $$< $$ | $$ |$$ | $$ |";
echo "$$ | $$ |/$$$$$$$ |$$ \_____ $$$$$$ \ $$ \__$$ |$$ \__$$ |";
echo "$$ | $$ |$$ $$ |$$ |$$ | $$ |$$ $$/ $$ $$/ ";
echo "$$/ $$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$/ $$$$$$/ ";
echo " ";
echo " ";
echo( =============================Menu==============================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo %%A %%B
echo(
echo( ===============================================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::********************************************************************************************
:menu_[1] Play DJ Buzz Radio
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching DJ Buzz Radio ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\DJBuzzRadio.vbs
Set URL=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[2] Play David Guetta Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching David Guetta Mix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\David_Guetta_Miami.vbs
Set URL=http://hackoo.alwaysdata.net/David_Guetta_Miami_2014.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[3] Play Ibiza Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Ibiza Mix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL=http://hackoo.alwaysdata.net/IbizaMix.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[4] Play Avicii Mega Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Avicii Megamix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL="http://hackoo.alwaysdata.net/Best of Avicii Megamix 2014.mp3"
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[5] Play Mega Mix 90
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Mega Mix 90 ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL="http://hackoo.alwaysdata.net/Megamix 90.mp3"
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[6] Stop the music
cls & color 0C
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Stopping the music ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo Dim Sound
echo Set Sound = CreateObject("WMPlayer.OCX"^)
echo Sound.URL = URL
echo Sound.settings.volume = 100
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
echo End Sub
)>%~2
::*********************************************************************************************
:Tab
set "x="
For /L %%I In (1,1,%1) Do Set "x=!x! "
REM ^-- this is a TAB
goto :eof
::*********************************************************************************************
:SkipLine
For /L %%I In (1,1,%1) Do Echo(
Goto:Eof
:EOF
EXIT
::*********************************************************************************************
Sub stop()
Member of WMPLib.IWMPControls
Stops play of media
来自对象浏览器。
所以Sound.Controls.stop
.
我正在批量制作游戏,我想在玩家'battling'时播放音乐。我设法播放了音乐,但是当玩家完成战斗后我似乎无法停止音乐。
@echo off
set "file=BattleMusic.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
start /min sound.vbs'
那是我的音乐剧本。关于播放器完成后如何停止它的任何想法?
@echo off
set "file=BattleMusic.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
start /min sound.vbs
for /f "tokens=2" %%i in ('tasklist ^|find "wscript.exe"') do set pid=%%i
echo press any key to stop the sound
pause >nul
taskkill /f /pid %pid%
当然这可能会有问题,如果另一个 wscript.exe
是 运行。但是您可以在启动您的之前保存他们的 PID,并且仅停止 "the new one".
您必须终止进程 wscript.exe
看看这个带有动态菜单的例子,其中有一个停止音乐的选项:
@echo off
setlocal enabledelayedexpansion
Set vbsfile=%temp%\Intro.vbs
Set URL=http://hackoo.alwaysdata.net/Intro_DJ.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
Set MyFile=%~f0
Set ShorcutName=DJ Batch Music Player
(
echo Call Shortcut("%MyFile%","%ShorcutName%"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo Dim objShell,DesktopPath,objShortCut,MyTab
echo Set objShell = CreateObject("WScript.Shell"^)
echo MyTab = Split(CheminApplication,"\"^)
echo If Nom = "" Then
echo Nom = MyTab(UBound(MyTab^)^)
echo End if
echo DesktopPath = objShell.SpecialFolders("Desktop"^)
echo Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo objShortCut.TargetPath = Dblquote(CheminApplication^)
echo ObjShortCut.IconLocation = "Winver.exe,0"
echo objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo DblQuote = Chr(34^) ^& Str ^& Chr(34^)
echo End Function
echo ^'**********************************************************************************************
) > %temp%\Shortcutme.vbs
Start /Wait %temp%\Shortcutme.vbs
Del %temp%\Shortcutme.vbs
::****************************************************************************************************
Title DJ Batch Music Player by Hackoo 2015
:menuLOOP
Color 0A & Mode con cols=78 lines=25
echo(
echo ===============================================================
echo "/ | / | / | ";
echo "$$ | $$ | ______ _______ $$ | __ ______ ______ ";
echo "$$ |__$$ | / \ / |$$ | / | / \ / \ ";
echo "$$ $$ | $$$$$$ |/$$$$$$$/ $$ |_/$$/ /$$$$$$ |/$$$$$$ |";
echo "$$$$$$$$ | / $$ |$$ | $$ $$< $$ | $$ |$$ | $$ |";
echo "$$ | $$ |/$$$$$$$ |$$ \_____ $$$$$$ \ $$ \__$$ |$$ \__$$ |";
echo "$$ | $$ |$$ $$ |$$ |$$ | $$ |$$ $$/ $$ $$/ ";
echo "$$/ $$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$/ $$$$$$/ ";
echo " ";
echo " ";
echo( =============================Menu==============================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo %%A %%B
echo(
echo( ===============================================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::********************************************************************************************
:menu_[1] Play DJ Buzz Radio
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching DJ Buzz Radio ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\DJBuzzRadio.vbs
Set URL=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[2] Play David Guetta Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching David Guetta Mix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\David_Guetta_Miami.vbs
Set URL=http://hackoo.alwaysdata.net/David_Guetta_Miami_2014.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[3] Play Ibiza Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Ibiza Mix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL=http://hackoo.alwaysdata.net/IbizaMix.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[4] Play Avicii Mega Mix
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Avicii Megamix ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL="http://hackoo.alwaysdata.net/Best of Avicii Megamix 2014.mp3"
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[5] Play Mega Mix 90
cls & color 0A
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Launching Mega Mix 90 ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\IbizaMix.vbs
Set URL="http://hackoo.alwaysdata.net/Megamix 90.mp3"
Call:Play %URL% %vbsfile%
Start %vbsfile%
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:menu_[6] Stop the music
cls & color 0C
Call:SkipLine 10
Call:Tab 3
echo %x% Please Wait for a while .. Stopping the music ...
Taskkill /IM "wscript.exe" /F >nul 2>&1
TimeOut /T 1 /NoBreak>nul
GOTO:menuLOOP
::********************************************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo Dim Sound
echo Set Sound = CreateObject("WMPlayer.OCX"^)
echo Sound.URL = URL
echo Sound.settings.volume = 100
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
echo End Sub
)>%~2
::*********************************************************************************************
:Tab
set "x="
For /L %%I In (1,1,%1) Do Set "x=!x! "
REM ^-- this is a TAB
goto :eof
::*********************************************************************************************
:SkipLine
For /L %%I In (1,1,%1) Do Echo(
Goto:Eof
:EOF
EXIT
::*********************************************************************************************
Sub stop()
Member of WMPLib.IWMPControls
Stops play of media
来自对象浏览器。
所以Sound.Controls.stop
.