mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-02 10:59:14 +01:00
Enhance play-mp3.ps1 and play-m3u.ps1
This commit is contained in:
parent
cd34307547
commit
9bd33214b1
@ -9,6 +9,7 @@ param($Filename = "")
|
||||
if ($Filename -eq "" ) { $Filename = read-host "Enter the M3U playlist filename" }
|
||||
|
||||
try {
|
||||
if (-not(test-path "$Filename" -pathType leaf)) { throw "Can't access playlist file: $Filename" }
|
||||
$Lines = get-content $Filename
|
||||
|
||||
add-type -assemblyName presentationCore
|
||||
@ -16,21 +17,22 @@ try {
|
||||
|
||||
for ([int]$i=0; $i -lt $Lines.Count; $i++) {
|
||||
$Line = $Lines[$i]
|
||||
if ($Line[0] -ne "#") {
|
||||
$FullPath = (get-childItem "$Line").fullname
|
||||
do {
|
||||
$MediaPlayer.open($FullPath)
|
||||
$Milliseconds = $MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds
|
||||
} until ($Milliseconds)
|
||||
[int]$Minutes = $Milliseconds / 60000
|
||||
[int]$Seconds = ($Milliseconds / 1000) % 60
|
||||
"▶️Playing 🎵$Line ($($Minutes):$Seconds) ..."
|
||||
$MediaPlayer.Volume = 1
|
||||
$MediaPlayer.play()
|
||||
start-sleep -milliseconds $Milliseconds
|
||||
$MediaPlayer.stop()
|
||||
$MediaPlayer.close()
|
||||
}
|
||||
if ($Line[0] -eq "#") { continue }
|
||||
if (-not(test-path "$Line" -pathType leaf)) { throw "Can't access audio file: $Line" }
|
||||
$FullPath = (get-childItem "$Line").fullname
|
||||
$Filename = (get-item "$FullPath").name
|
||||
do {
|
||||
$MediaPlayer.open("$FullPath")
|
||||
$Milliseconds = $MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds
|
||||
} until ($Milliseconds)
|
||||
[int]$Minutes = $Milliseconds / 60000
|
||||
[int]$Seconds = ($Milliseconds / 1000) % 60
|
||||
"▶️Playing 🎵$Filename ($($Minutes.ToString('00')):$($Seconds.ToString('00'))) ..."
|
||||
$MediaPlayer.Volume = 1
|
||||
$MediaPlayer.play()
|
||||
start-sleep -milliseconds $Milliseconds
|
||||
$MediaPlayer.stop()
|
||||
$MediaPlayer.close()
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
|
@ -9,19 +9,21 @@ param($Filename = "")
|
||||
if ($Filename -eq "" ) { $Filename = read-host "Enter the MP3 filename" }
|
||||
|
||||
try {
|
||||
$Filename = resolve-path -path "$Filename" -relative
|
||||
if (-not(test-path "$Filename" -pathType leaf)) { throw "Can't access audio file: $Filename" }
|
||||
$FullPath = (get-childItem $Filename).fullname
|
||||
$Filename = (get-item "$FullPath").name
|
||||
|
||||
add-type -assemblyName PresentationCore
|
||||
$MediaPlayer = new-object System.Windows.Media.MediaPlayer
|
||||
|
||||
$FullPath = (get-childItem $Filename).fullname
|
||||
do {
|
||||
$MediaPlayer.open($FullPath)
|
||||
$Milliseconds = $MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds
|
||||
} until ($Milliseconds)
|
||||
|
||||
[int]$Minutes = $Milliseconds / 60000
|
||||
[int]$Seconds = ($Milliseconds / 1000) % 60
|
||||
"▶️Playing 🎵$Filename ($($Minutes):$Seconds) ..."
|
||||
"▶️Playing 🎵$Filename ($($Minutes.ToString('00')):$($Seconds.ToString('00'))) ..."
|
||||
$MediaPlayer.Volume = 1
|
||||
$MediaPlayer.play()
|
||||
start-sleep -milliseconds $Milliseconds
|
||||
|
Loading…
Reference in New Issue
Block a user