How can I play a sound file from a Windows batch file?

Batch fileUse the start command to start the program associated with the file. For example, if you wanted to open the player to play "music.mp3" in the command line or batch file you could type the below command.

start music.mp3

If the sound file has a space in the filename, surround the filename in quotes as shown in the example below.

start c:\music\"my song.mp3"

Tip: Using the start command opens the file in the default audio player. This means by default audio files open in Windows Media Player. However, if the user has installed a different audio program that has re-associated the audio files it opens in that program. If you want Windows Media Player to play the audio file regardless of what other audio players have been installed, try the below alternative solution.

Alternative solution

Using the Windows mplay32.exe, mplayer.exe, or wmplayer.exe file included with Microsoft Windows allows you to play Windows sound files. Depending on your version of Windows will depend on what file you'll run. Windows 95 and 98 users use mplayer, Windows XP and 2000 users use mplay32 as shown in the examples below, and Windows Vista and Windows 7 users use wmplayer.

As can be seen in the example below, we're using mplay32 as the program to play the file. The /play and /close switches are used to tell the program to play the file once open and then close when done. Finally, the remainder of the line is the full path to where the audio file is stored. In this example, we're playing the Windows chimes file.

mplay32 /play /close c:\windows\media\chimes.wav

If the file or directory has a space in it, make sure to include the full path in quotes as shown below.

mplay32 /play /close "c:\windows\media\windows xp error.wav"

Finally, earlier versions of the Media Player (mplayer) can only play .wav, .mid, *.cda, *.avi, *.asf files. If you're trying to play .mp3 files or other audio files, this program will not work. If you need to play other media files, use an alternative command line media player that is not included with Windows. The later version of Windows wmplayer command is capable of playing .mp3 files as well as all other media files Windows Media Player is capable of playing.

Opening a sound file in a different program

To play an audio file in a different media player, set the path to the directory of where the alternative media player is or move into the directory that contains the audio file. Otherwise you'll get an error message indicating that the command is not recognized.

For example, assuming you wanted to play a MP3 file in the VLC media player. You could move into the C:\Program files\VideoLan\VLC directory or add the directory to your path. From this directory, type the below command to execute and start playing the MP3 file in VLC. Keep in mind that the mplay32 options mentioned above (/play and /close) do not work for every media player including VLC.

vlc "c:\music\my song.mp3"

Additional information

  • See the start command for further information on this command and additional examples.