PowerShell/scripts/play-files.ps1

43 lines
1.1 KiB
PowerShell
Raw Normal View History

2024-10-01 15:11:03 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2024-11-21 08:17:47 +01:00
Plays audio files
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2024-11-21 08:17:47 +01:00
This PowerShell script plays the given audio files (supporting .MP3 and .WAV format).
.PARAMETER filePattern
Specifies the file pattern ('*' by default)
2021-07-13 21:10:02 +02:00
.EXAMPLE
2024-11-21 08:17:47 +01:00
PS> ./play-files.ps1 *.mp3
Playing '01 Sandy beaches - strong waves.mp3' (02:54) ...
...
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-09-06 21:42:04 +02:00
.NOTES
Author: Markus Fleschutz | License: CC0
2021-05-01 09:26:26 +02:00
#>
2024-11-21 08:17:47 +01:00
param([string]$filePattern = "*")
2021-05-01 09:26:26 +02:00
try {
2024-11-21 08:17:47 +01:00
$stopWatch = [system.diagnostics.stopwatch]::startNew()
$files = (Get-ChildItem -path "$filePattern" -attributes !Directory)
[int]$count = 0
foreach ($file in $files) {
if ("$file" -like "*.mp3") {
& "$PSScriptRoot/play-mp3.ps1" "$file"
$count++
2021-05-01 10:23:46 +02:00
} elseif ("$File" -like "*.wav") {
2024-11-21 08:17:47 +01:00
& "$PSScriptRoot/play-mp3.ps1" "$file"
$count++
2021-05-01 09:26:26 +02:00
} else {
2024-11-21 08:17:47 +01:00
"Skipping $file (no audio file)..."
2021-05-01 09:26:26 +02:00
}
}
2024-11-21 08:17:47 +01:00
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Played $count audio files for $($elapsed)s."
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-05-01 09:26:26 +02:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-05-01 09:26:26 +02:00
exit 1
}