Advertisement
metalx1000

Play all Music files in a directory - mp3 ; wma

Jun 25th, 2014
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -AssemblyName presentationCore
  2. $mediaPlayer = New-Object system.windows.media.mediaplayer
  3. $path = "c:\mu\"
  4. $files = Get-ChildItem -path $path -include *.mp3,*.wma -recurse
  5. foreach($file in $files)
  6. {
  7.  "Playing $($file.BaseName)"
  8.  $mediaPlayer.open([uri]"$($file.fullname)")
  9.  $mediaPlayer.Play()
  10.  Start-Sleep -seconds 2 # need to wait for mediaPlayer to determine file duration
  11.  Start-Sleep -seconds $mediaPlayer.NaturalDuration.TimeSpan.TotalSeconds
  12.  $mediaPlayer.Stop()
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement