From 8e384b6d67c1ec1e8af112f8a5be2961fe22bb39 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sat, 20 Feb 2021 12:08:05 +0100 Subject: [PATCH] Improved the scripts --- Scripts/play-m3u.ps1 | 12 +++++++++++- Scripts/play-mp3.ps1 | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Scripts/play-m3u.ps1 b/Scripts/play-m3u.ps1 index 1ab613d6..a5081913 100644 --- a/Scripts/play-m3u.ps1 +++ b/Scripts/play-m3u.ps1 @@ -13,6 +13,7 @@ if ($Filename -eq "" ) { } try { + write-progress "Reading playlist '$Filename' ..." $Lines = get-content $Filename add-type -assemblyName presentationCore @@ -21,8 +22,17 @@ try { for ([int]$i=0; $i -lt $Lines.Count; $i++) { $Line = $Lines[$i] if ($Line[0] -ne "#") { - $MediaPlayer.open("$Line") + write-output "Playing '$Line' ..." + $FullPath = (get-childItem "$Line").fullname + do { + $MediaPlayer.open("$Line") + $Duration = $MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds + } until ($Duration) + $MediaPlayer.Volume = 1 $MediaPlayer.play() + start-sleep -milliseconds $Duration + $MediaPlayer.stop() + $MediaPlayer.close() } } exit 0 diff --git a/Scripts/play-mp3.ps1 b/Scripts/play-mp3.ps1 index 048681df..8f9fbe48 100755 --- a/Scripts/play-mp3.ps1 +++ b/Scripts/play-mp3.ps1 @@ -13,10 +13,20 @@ if ($Filename -eq "" ) { } try { - add-type -assemblyName presentationCore - $MediaPlayer = new-object system.windows.media.mediaplayer - $MediaPlayer.open("$Filename") + add-type -assemblyName PresentationCore + $MediaPlayer = new-object System.Windows.Media.MediaPlayer + + $FullPath = (get-childItem $Filename).fullname + do { + $MediaPlayer.open($FullPath) + $Duration = $MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds + } until ($Duration) + write-progress "Playing $Filename ..." + $MediaPlayer.Volume = 1 $MediaPlayer.play() + start-sleep -milliseconds $Duration + $MediaPlayer.stop() + $MediaPlayer.close() exit 0 } catch {