How to make music play in background of batch game

前端 未结 4 1590
抹茶落季
抹茶落季 2021-01-07 02:16

I am making a batch game in notepad and I was wondering how I can play the file music in the background.

I have this:

@echo off
start Music.mp3         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 02:44

    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
    

    Alternatively this:

    @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
    

    This creates a vbs that starts the music without a new window.


    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---
    
    
       
        
    
    

提交回复
热议问题