PowerShell/docs/play-files.md

90 lines
2.1 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *play-files.ps1* Script
===========================
2021-11-08 21:36:42 +01:00
2025-01-17 08:31:53 +01:00
This PowerShell script plays the given audio files (supporting .MP3 and .WAV format).
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2021-11-08 21:36:42 +01:00
```powershell
2025-01-17 08:31:53 +01:00
/Repos/PowerShell/scripts/play-files.ps1 [[-filePattern] <String>] [<CommonParameters>]
2021-11-08 21:36:42 +01:00
2025-01-17 08:31:53 +01:00
-filePattern <String>
Specifies the file pattern ('*' by default)
2021-11-08 21:36:42 +01:00
Required? false
Position? 1
Default value *
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Example
-------
2021-11-08 21:36:42 +01:00
```powershell
2025-01-17 08:31:53 +01:00
PS> ./play-files.ps1 *.mp3
▶️ Playing '01 Sandy beaches - strong waves.mp3' (02:54) ...
...
2021-11-08 21:36:42 +01:00
```
2023-07-29 10:04:38 +02:00
Notes
-----
2022-11-17 19:46:02 +01:00
Author: Markus Fleschutz | License: CC0
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Related Links
-------------
2021-11-08 21:36:42 +01:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
2025-01-17 08:31:53 +01:00
Plays audio files
2022-11-17 20:02:26 +01:00
.DESCRIPTION
2025-01-17 08:31:53 +01:00
This PowerShell script plays the given audio files (supporting .MP3 and .WAV format).
.PARAMETER filePattern
Specifies the file pattern ('*' by default)
2022-11-17 20:02:26 +01:00
.EXAMPLE
2025-01-17 08:31:53 +01:00
PS> ./play-files.ps1 *.mp3
▶️ Playing '01 Sandy beaches - strong waves.mp3' (02:54) ...
...
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2025-01-17 08:31:53 +01:00
param([string]$filePattern = "*")
2022-11-17 20:02:26 +01:00
try {
2025-01-17 08:31:53 +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++
2022-11-17 20:02:26 +01:00
} elseif ("$File" -like "*.wav") {
2025-01-17 08:31:53 +01:00
& "$PSScriptRoot/play-mp3.ps1" "$file"
$count++
2022-11-17 20:02:26 +01:00
} else {
2025-01-17 08:31:53 +01:00
"Skipping $file (no audio file)..."
2022-11-17 20:02:26 +01:00
}
}
2025-01-17 08:31:53 +01:00
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ Played $count audio files for $($elapsed)s."
2022-11-17 20:02:26 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2025-01-17 08:37:30 +01:00
*(page generated by convert-ps2md.ps1 as of 01/17/2025 08:37:11)*