Skip to content

Play-M3u

Plays a .M3U playlist

param([string]$filename = "")

try {
	if ($filename -eq "" ) { $filename = Read-Host "Enter the path to the .M3U playlist file" }

	if (-not(Test-Path "$filename" -pathType leaf)) { throw "Can't access playlist file: $filename" }
	$lines = Get-Content $filename

	Add-Type -assemblyName presentationCore
	$MediaPlayer = New-Object system.windows.media.mediaplayer

	foreach ($line in $lines) {
		if ($line[0] -eq "#") { continue }
		if (-not(Test-Path "$line" -pathType leaf)) { throw "Can't access audio file: $line" }
		$fullPath = (Get-ChildItem "$line").fullname

		& "$PSScriptRoot/play-mp3.ps1" $fullPath
	}
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the path to the playlist

An interactive directory of PowerShell scripts.