如何在批处理游戏的背景下播放音乐 [英] How to make music play in background of batch game
问题描述
我正在用记事本制作批处理游戏,我想知道如何在后台播放文件音乐.
I am making a batch game in notepad and I was wondering how I can play the file music in the background.
我有这个:
@echo off
start Music.mp3
Pause
它的作用是启动我名为Music.mp3的音乐,但会在一个弹出的单独窗口中启动它.我想要的是它开始播放,而不是在窗口中弹出.我也希望它能在我玩游戏时启动并在后台播放.
What this does is it starts my music named Music.mp3 but it starts it in a separate window that pops up. What I want is for it to start playing, but not pop up in a window. I also want it to start and play in the background as I play my game.
有什么办法可以做到这一点?
Any ways I could do this?
推荐答案
使用命令处理器的内部命令可以获得的最接近的结果只能最小化一个窗口.如果您真的想对其进行后台处理",则该脚本将很长且令人困惑.
The closest your can get using internal commands of a command processor can only minimize a window. If you really want to "background" it, the script will be long and confusing.
start /min /c "" Music.mp3
或者,这是
@echo off
set "file=track12.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
cscript.exe //nologo sound.vbs
这会创建一个vbs
,它会在没有新窗口的情况下开始播放音乐.
This creates a vbs
that starts the music without a new window.
用户LưuVĩnhPhúc建议,使用混合脚本可以防止清理问题.
User Lưu Vĩnh Phúc has suggested, using a hybrid script prevents the issue of cleaning up.
@echo off
rem ----START OF BATCH CODE---
rem You can paste your entire batch code down here, and use
rem the cscript command whenever you want to play the sound.
cscript //nologo "%~f0?.wsf" //job:VBS
rem ----END OF BATCH CODE---
<package>
<job id="JS">
<script language="VBScript">
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "%file%"
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep (int(Sound.currentmedia.duration)+1)*1000)
</script>
</job>
这篇关于如何在批处理游戏的背景下播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!