-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
play-files.ps1
executable file
·42 lines (39 loc) · 1.06 KB
/
play-files.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Plays audio files
.DESCRIPTION
This PowerShell script plays the given audio files (supporting .MP3 and .WAV format).
.PARAMETER filePattern
Specifies the file pattern ('*' by default)
.EXAMPLE
PS> ./play-files.ps1 *.mp3
▶️ Playing '01 Sandy beaches - strong waves.mp3' (02:54) ...
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$filePattern = "*")
try {
$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++
} elseif ("$File" -like "*.wav") {
& "$PSScriptRoot/play-mp3.ps1" "$file"
$count++
} else {
"Skipping $file (no audio file)..."
}
}
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Played $count audio files for $($elapsed)s."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}