How to play a sound file from a Windows batch file
Use 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.
If the sound file has a space in the file name, surround the file name 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, which means by default, audio files open in Windows Media Player. However, if the computer has a different audio program that has 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 have been installed, try the alternative solution below.
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 which file you run. Windows 95 and 98 users should use mplayer, Windows XP and 2000 users should use mplay32 (as shown in the examples below), and Windows Vista and Windows 7 users should use wmplayer.
Windows Vista, Windows 7, and Windows 8 wmplayer examples
The command below will start the example.mp3 audio file and play the file.
start wmplayer c:\mp3\example.mp3
Like the example above, when entering the path to the MP3 or other media file, make sure to specify the complete path, including the drive letter. If the directory or audio file name has a space in it, make sure to place quotes around the full path, as shown below.
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 a series of different files, you may 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 can be seen in the example below, we are using mplay32 as the program to play the file. The /play and /close switches are used to 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, 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, 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 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 located or move into the directory that contains the audio file. Otherwise, you will get an error message indicating that the command is not recognized.
For example, if you wanted to play an MP3 file in the VLC 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 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"