Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play audio file on windows from command line?

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

like image 328
Kilo Avatar asked Oct 15 '09 00:10

Kilo


3 Answers

Old question, new answer - you could use PowerShell:

powershell -c (New-Object Media.SoundPlayer 'c:\PathTo\YourSound.wav').PlaySync();
like image 175
joshcomley Avatar answered Sep 18 '22 09:09

joshcomley


I have used cmdmp3. Very lightweight at 28Kb.

like image 37
pathe3 Avatar answered Sep 18 '22 09:09

pathe3


Use VBScript:

Set objArgs = Wscript.Arguments

if (objArgs.Count = 0) then
    Wscript.echo "I need a sound file as argument!"
    WScript.Quit 123
end if
Wscript.echo "Playing: " & objArgs(0) & "..."

Set objPlayer = createobject("Wmplayer.OCX.7")

With objPlayer  ' saves typing
    .settings.autoStart = True
    .settings.volume = 50  ' 0 - 100
    .settings.balance = 0  ' -100 to 100
    .settings.enableErrorDialogs = False
    .enableContextMenu = False
    .URL = objArgs(0)
    WScript.Sleep(10000)  ' time to load and start playing
    '.Controls.Pause()  ' stop
End With

MsgBox "if WMP is still playing, clicking OK will end it", _
    vbInformation, "WMP Demo finished"

If the VBScript process ends, the Media Player ends too, you have to wait for it (I don't need it, my sounds are only some seconds long).

I used this for my special case today: https://groups.google.com/forum/#!topic/microsoft.public.scripting.vbscript/gfOOvnN8t-U

like image 37
Mayra Delgado Avatar answered Sep 17 '22 09:09

Mayra Delgado