Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play mp3 with powershell (simple)?

Tags:

powershell

mp3

How do I play mp3 with Powershell?

What I tried:

powershell -c (New-Object Media.SoundPlayer "Track.mp3").Play();
like image 880
Heaven Avatar asked Sep 17 '14 16:09

Heaven


2 Answers

You can play an mp3 from powershell, you just need to use

 system.windows.media.mediaplayer 

instead of

 System.Media.SoundPlayer

It works in Windows 10

I followed a snipped from http://eddiejackson.net/wp/?p=9268

# Play a single file
Add-Type -AssemblyName presentationCore
$mediaPlayer = New-Object system.windows.media.mediaplayer
$mediaPlayer.open('C:\sounds\bike.mp3')
$mediaPlayer.Play()
like image 145
Max Carroll Avatar answered Oct 15 '22 14:10

Max Carroll


This is an old question but I just went through this so if anyone is interested in learning or knowing how to do this in a more simple manner use the following answer.

As long as you have a media player that has good command line switches such as VLC and other similar types of versatile players (perhaps media player classic) you CAN make a one line command to run a MP3 file. Here is my example, enjoy! :)

& 'C:\Program Files\VideoLAN\VLC\vlc.exe' --qt-start-minimized --play-and-exit --qt-notification=0 "D:\SystemSettings\51Hz.mp3"

This would run 51Hz.mp3 file with neither notifications to take place nor any other user interaction.

like image 25
nndhawan Avatar answered Oct 15 '22 14:10

nndhawan