Last active
November 27, 2019 08:38
-
-
Save megadix/05e2b8d6a649196ef9ab692dd186970f to your computer and use it in GitHub Desktop.
PowerShell: enqueue and play a random song with VLC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function playMusicForProgramming() { | |
param( | |
[int] $n = 1 | |
) | |
playRandomMusic $n 'C:\download\music\musicforprogramming.net' | |
} | |
function playAmbientMusic() { | |
param( | |
[int] $n = 1 | |
) | |
playRandomMusic $n 'C:\download\music\ambient' -recurse -folders | |
} | |
function playRandomMusic() { | |
param( | |
[int] $n = 1, | |
[string] $folder = 'C:\download\music', | |
[Switch] $recurse = $true, | |
[Switch] $folders = $false | |
) | |
$first = $true; | |
For ($i = 1; $i -le $n; $i++) { | |
if ($folders) { | |
$file = dir -Path "${folder}\*" -Directory -Recurse:$recurse | |
} | |
else { | |
$excludes = ("*.jpg", "*.pdf", "*.txt"); | |
$file = dir -Path "${folder}\*" -File -Recurse:$recurse -Exclude $excludes | |
} | |
$file = $file | Get-Random | |
echo "Enqueueing to playlist: ${file}" | |
$cmd = 'C:\Program Files\VideoLAN\VLC\vlc.exe' | |
$params = '--one-instance', '--playlist-enqueue', $file.FullName | |
& $cmd $params | |
if ($first) { | |
# Allows VLC to start playing first song | |
Start-Sleep -s 1 | |
$first = $false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can put this function in your PowerShell profile, so any time you want some music to play, you can issue one of these commands on PS terminal: