How to play audio file on windows from command line?

Viewed 63253

In Windows, is there a simple way (i.e. something you could type on a single command line) to just play a couple of .mp3 files and then exit on its own?

wmplayer, for example, does not seem to exit when finished, forcing the harried user to hunt it down and click it closed every time. (wmplayer 11 also seems to strangely repeat some files if you pass it a list.) (The older (1990's) versions of 'mplayer' used to support a '/close' command line option, but it doesn't seem to work in wmplayer 11.)

I'd prefer to use something that everyone will have on their machine (like wmplayer, quicktime...)

11 Answers

I've found that the fastest way to play .mp3 files in Windows commandline is mpeg123

I know it's not available on people's machine per default, but from my point of view, Microsoft's own players are not consistently available over different versions either.

I'm using it on a project where the execution time is essential, and features like only playing certain frames makes is very useful. I find this (in my configuration) faster than the cmdmp3 and vbscript examples mentioned in this thread.

My syntax to only play certain frames of an .mp3 file : mpg123.exe -k 2 -n 3 -q -1 -4 beep.mp3

Here are few scripts.

mediarunner.bat - it uses windows media player active x objects so you cannot used if there's no installed Windows Media Player (though it usually comes packed with the Windows).Accepts only one argument - the path to the file you want to play.

spplayer.bat - uses SP Voice objects but can play only .wav files.Again it accepts as only argument the path to the file you want to play.

soundplayer.bat - uses Internet Explorer objects and specific bgsound tag that can be used only in internet explorer.Can play .mp3,wav,.. files. It can accepts two arguments. The file you want to play and the sound volume (a number between -10000 to 0) :

 call soundplayer.bat "C:\Windows\Media\Windows Navigation Start.wav" 0

You can use fmedia to play audio files from Windows terminal:

fmedia file1.mp3 file2.mp3

This command will start the playback of file.mp3, then file2.mp3, and then quit after the files have finished playing.

If you wish to do it in background, add --background switch to your command:

fmedia file.ogg --background

This command will start a new process in background and detach from your console immediately.

fmedia is a portable application (works without installation) and consumes very small amount of system resources. Also, its startup time is instantaneous.

P.S. Use command fmedia.exe --install to add it to your %PATH% environment variable, otherwise you need to execute it with full path, e.g. D:\fmedia\fmedia.exe

If you need something cross-platform, mplayer works well on linux and windows and is compatible with npm's play-sound.

Related