Files
PowerShell/docs/play-m3u.md
Markus Fleschutz d8690419ea Updated the manuals
2025-06-22 10:38:33 +02:00

89 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

The *play-m3u.ps1* Script
===========================
This PowerShell script plays the given playlist (in .M3U file format)
Parameters
----------
```powershell
/Repos/PowerShell/scripts/play-m3u.ps1 [[-filename] <String>] [<CommonParameters>]
-filename <String>
Specifies the path to the playlist
Required? false
Position? 1
Default value
Accept pipeline input? false
Aliases
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
Example
-------
```powershell
PS> ./play-m3u.ps1 C:\MyPlaylist.m3u
Playing '01 Sandy beach - strong waves.mp3' (02:54) ...
...
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.SYNOPSIS
Plays a .M3U playlist
.DESCRIPTION
This PowerShell script plays the given playlist (in .M3U file format)
.PARAMETER filename
Specifies the path to the playlist
.EXAMPLE
PS> ./play-m3u.ps1 C:\MyPlaylist.m3u
▶️ Playing '01 Sandy beach - strong waves.mp3' (02:54) ...
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
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 in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
*(page generated by convert-ps2md.ps1 as of 06/22/2025 10:37:40)*