好吧,我从Batch开始,我想知道如何在不使用任务管理器退出.bat文件时停止我执行的背景音频。我用这个来执行音频并循环它:
set "file=music1.mp3"
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%file%"
echo Sound.settings.volume = 100
echo Sound.settings.setMode "loop", True
echo Sound.Controls.play
echo While Sound.playState ^<^> 1
echo WScript.Sleep 100
echo Wend
)>sound.vbs
start /min sound.vbs
另一个问题是如何划分循环,因为我不知道如何在一定数量的循环中停止循环。提前谢谢。
答案 0 :(得分:0)
此代码的灵感来自:How do I play music on loop in batch?
@echo off
Title Play Music in loop and stop it
Call:StopMusic
echo We play "Intro_DJ.mp3" with a volume of 80
Call:PlayMusic http://hackoo.alwaysdata.net/Intro_DJ.mp3 80
echo(
echo Hit any key to stop the music and play another file
pause>nul
Call:StopMusic
cls
Call:PlayMusic http://hackoo.alwaysdata.net/Matrix.mp3 100
echo(
echo We play "Matrix.mp3" with a volume of 100
echo(
echo Hit any key to stop the music in loop
pause>nul
Call:StopMusic
Exit /b
::************************************************************
:PlayMusic <Media_URL> <Volume>
(
echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%1"
echo Sound.settings.volume = %2
echo Sound.settings.setMode "loop", True
echo Sound.Controls.play
echo While Sound.playState ^<^> 1
echo WScript.Sleep 100
echo Wend
)>%~n0.vbs
start "" "%~n0.vbs" %1 %2
Exit /b
::************************************************************
:StopMusic
Taskkill /IM "wscript.exe" /F>nul 2>&1
Exit /b
::************************************************************