2021-02-16 20:03:32 +01:00
|
|
|
#!/bin/powershell
|
|
|
|
<#
|
|
|
|
.SYNTAX ./play-mp3.ps1 [<MP3-file>]
|
2021-02-17 20:09:44 +01:00
|
|
|
.DESCRIPTION plays the given sound file (MP3 file format)
|
2021-02-16 20:03:32 +01:00
|
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
param($Filename = "")
|
|
|
|
|
2021-02-18 20:17:55 +01:00
|
|
|
if ($Filename -eq "" ) {
|
|
|
|
$Filename = read-host "Enter the MP3 filename"
|
|
|
|
}
|
|
|
|
|
2021-02-16 20:03:32 +01:00
|
|
|
try {
|
2021-02-17 20:09:44 +01:00
|
|
|
add-type -assemblyName presentationCore
|
|
|
|
$MediaPlayer = new-object system.windows.media.mediaplayer
|
|
|
|
$MediaPlayer.open("$Filename")
|
|
|
|
$MediaPlayer.play()
|
|
|
|
|
2021-02-16 20:03:32 +01:00
|
|
|
exit 0
|
|
|
|
} catch {
|
|
|
|
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|