Update play-mp3.ps1

This commit is contained in:
Markus Fleschutz 2021-11-26 17:17:18 +01:00
parent b274a812e7
commit fa952666d4

View File

@ -1,9 +1,9 @@
<# <#
.SYNOPSIS .SYNOPSIS
Plays a sound file (MP3 format) Plays a MP3 sound file
.DESCRIPTION .DESCRIPTION
This script plays a sound file (in .MP3 file format). This script plays a sound file in .MP3 file format.
.PARAMETER Filename .PARAMETER Path
Specifies the path to the .MP3 file Specifies the path to the .MP3 file
.EXAMPLE .EXAMPLE
PS> ./play-mp3 C:\thunder.mp3 PS> ./play-mp3 C:\thunder.mp3
@ -13,13 +13,13 @@
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
#> #>
param([string]$Filename = "") param([string]$Path = "")
try { try {
if ($Filename -eq "" ) { $Filename = read-host "Enter the MP3 filename" } if ($Path -eq "" ) { $Path = read-host "Enter the path to the MP3 sound file" }
if (-not(test-path "$Filename" -pathType leaf)) { throw "Can't access audio file: $Filename" } if (-not(test-path "$Path" -pathType leaf)) { throw "Can't access sound file: $Path" }
$FullPath = (get-childItem $Filename).fullname $FullPath = (get-childItem $Path).fullname
$Filename = (get-item "$FullPath").name $Filename = (get-item "$FullPath").name
add-type -assemblyName PresentationCore add-type -assemblyName PresentationCore
@ -32,7 +32,7 @@ try {
[int]$Minutes = $Milliseconds / 60000 [int]$Minutes = $Milliseconds / 60000
[int]$Seconds = ($Milliseconds / 1000) % 60 [int]$Seconds = ($Milliseconds / 1000) % 60
"▶️ Playing 🎵$Filename for $($Minutes.ToString('00')):$($Seconds.ToString('00')) sec..." "▶️ Playing $Filename for $($Minutes.ToString('00')):$($Seconds.ToString('00')) sec..."
$PreviousTitle = $host.ui.RawUI.WindowTitle $PreviousTitle = $host.ui.RawUI.WindowTitle
$host.ui.RawUI.WindowTitle = "▶️ $Filename" $host.ui.RawUI.WindowTitle = "▶️ $Filename"
$MediaPlayer.Volume = 1 $MediaPlayer.Volume = 1