Skip to content

Latest commit

 

History

History
89 lines (75 loc) · 2.14 KB

play-files.md

File metadata and controls

89 lines (75 loc) · 2.14 KB

The play-files.ps1 Script

This PowerShell script plays the given audio files (supporting .MP3 and .WAV format).

Parameters

/Repos/PowerShell/scripts/play-files.ps1 [[-filePattern] <String>] [<CommonParameters>]

-filePattern <String>
    Specifies the file pattern ('*' by default)
    
    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.

Example

PS> ./play-files.ps1 *.mp3
   ▶️ Playing '01 Sandy beaches - strong waves.mp3' (02:54) ...
   ...

Notes

Author: Markus Fleschutz | License: CC0

Related Links

https://github.com/fleschutz/PowerShell

Script Content

<#
.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
}

(page generated by convert-ps2md.ps1 as of 01/23/2025 12:15:24)