How to play a sound file from a Windows batch file

Updated: 03/12/2022 by Computer Hope
Batch file

If you're running a batch file on your computer, it can be useful to play audio on your computer speakers for a notification or alarm sound. You can use the start command in your batch file to launch an audio application and play the sound, audio recording, or music that you'd like to hear.

Examples

If you want the player to open and play "music.mp3" in the command line or batch file, you could type the following command.

start music.mp3

If the sound file has a space in the file name, surround the file name in quotes as shown in the following example.

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

Using the start command opens the file in the default audio player, which means by default, audio files open in Windows Media Player. However, if the computer has a different audio program that re-associated the audio files, the other program is used instead. If you want Windows Media Player to play the audio file regardless of what other audio players are installed, continue to the next section.

Alternative solution

The Windows Media Player can run from the command line or a batch file to play sound files. To ensure audio files are played using this application, include the "wmplayer" after the start command.

In Windows 10 and 11, the Media Player executable file is located at Program Files (x86)\Windows Media Player\wmplayer.exe. In previous versions of Windows, the Media Player executable was named mplay32.exe or mplayer.exe. Windows 95 and 98 users should use mplayer. Windows XP and 2000 users should use mplay32 (as shown in the following examples), and Windows Vista and Windows 7 users should use wmplayer.

Windows Vista, Windows 7, and Windows 8 wmplayer examples

The following command causes Windows Media Player to open and play the audio file example.mp3.

start wmplayer c:\mp3\example.mp3

In this example, always specify the complete path to the audio file, including the drive letter. If the directory or audio file name has a space in it, make sure to enclose the entire path and file name in double quotes, for example:

start wmplayer "c:\mp3\example audio.mp3"

Where is the wmplayer /close option?

Unfortunately, Microsoft has not included a /close option for wmplayer. If you need a close option to run several files, consider using the "/Playlist PlaylistName" switch to have Windows Media Player play a playlist. Alternatively, you can use another media player program, such as MPC-HC, which does have a /close option.

Windows XP and 2000 mplay32 examples

As shown in the following example, we use mplay32 as the program to play the file. The /play and /close switches tell the program to play the file 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 are playing the Windows chimes file.

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

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

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

Earlier versions of the Media Player (mplayer) can only play .wav, .mid, .cda, .avi, and .asf files. If you are 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 not included with Windows. The later version of the Windows wmplayer command can play .mp3 files and all other media files Windows Media Player can play.

Playing sound with a custom audio program

To play an audio file in a different media player, set the path to the directory where the alternative media player is located. Otherwise, you get an error message indicating that the command is not recognized.

For example, to play an MP3 file in the VLC (VideoLAN client) media player, you could move to the C:\Program Files\VideoLan\VLC directory or add the directory to your path. From this directory, type the following command to execute and start playing the MP3 file in VLC. Remember that the mplay32 options mentioned above (/play and /close) do not work for every media player, including VLC.

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