Skip to content

Instantly share code, notes, and snippets.

@alexmags
Created February 26, 2022 09:21
Show Gist options
  • Save alexmags/6a28c874e88786fddedd2c1efbd78096 to your computer and use it in GitHub Desktop.
Save alexmags/6a28c874e88786fddedd2c1efbd78096 to your computer and use it in GitHub Desktop.
Muzak for long running PowerShell scripts. Pointless
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent # files relative to here
$musakFilePath="$scriptDir\musak.mp3" # https://www.youtube.com/watch?v=FsoIfkNQYEg
$wmplayer = New-Object System.Windows.Media.MediaPlayer
$wmplayer.Open($musakFilePath)
Start-Sleep 2 # This allows the $wmplayer time to load the audio file
$duration = $wmplayer.NaturalDuration.TimeSpan.TotalSeconds
$wmplayer.Play()
$stopwatch=[system.diagnostics.stopwatch]::StartNew()
while ($stopwatch.Elapsed.Seconds -lt $duration)
{
Write-Progress -Activity "Doing stuff, please hold…" -status "$($stopwatch.Elapsed.Seconds) seconds" -percentComplete ($stopwatch.Elapsed.Seconds / $duration*100)
# do something
# break when done
start-Sleep -s 1
}
$wmplayer.Stop()
$wmplayer.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment