I have reference of : powershell 'system.windows.media.mediaplayer' Register-ObjectEvent, for handling audio files, using PowerShell. It shows code, for playing audio files, in a folder. But doesn't explains further or comment on its using.
What I want is PowerShell, to create a Windows Form, with select files dialog, basic icons, for play/pause/stop, and displaying its current time status,( how many minutes passed, remaining, on seek bar).
Here is code for reference:
Add-Type -AssemblyName PresentationCore
$_MediaPlayer = New-Object System.Windows.Media.MediaPlayer
$_MusicFolder = 'C:\Users\Making JESUS Proud\Music'
$_MusicFiles = Get-ChildItem -path $_MusicFolder -include *.mp3 -recurse
$duration = $null
foreach($_file in $_MusicFiles){
"Playing $($_file.BaseName)"
[uri]$_song = $_file.FullName
do {
$_MediaPlayer.Open($_song)
$_songDuration = $_MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds
}
until ($_songDuration)
$_MediaPlayer.Volume = 1
$_MediaPlayer.Play()
Start-Sleep -Milliseconds $_songDuration
$_MediaPlayer.Stop()
$_MediaPlayer.Close()
}
I am ready with GUI part, but I am not able to pull information from MediaPlayer class, regarding its timeline progress, and event handling to pause/stop/replay audio.
Documentation for class:
https://msdn.microsoft.com/en-us/library/System.Windows.Media.MediaPlayer%28v=vs.110%29.aspx
About time line related I have found, three following properties, but I don't understand them, properly.
MediaPlayer.NaturalDuration
MediaPlayer.Clock
MediaPlayer.Position