I was following a tutorial on how to control video using WPF mediaelement. For most parts, all is good except the rewind video function. I tried looking for solutions and came across on a thread that suggested pausing the video and changing the position of the video playback. So I tried this:
//timer updates the position of the slider
if(flagRewind == true)
{
try
{
if (playVideoMediaElement.NaturalDuration.HasTimeSpan)
{
//step the video back every second
playVideoMediaElement.Position -= TimeSpan.FromMilliseconds(1000);
videoSlider.Value = playVideoMediaElement.Position.TotalSeconds;
//we have re-winded to the zero position of the slider
if (videoSlider.Value <= 0)
{
//the video is done playing
playVideoMediaElement.Stop();
//get tag of button click, to change button icon appropriately (pause[||]/play [>])
tag = playPauseVideoButton.Tag.ToString();
//call method that changes the button image icon to either [||] or [>]
ChangePlayPauseButtonImageIcon();
IsPlaying(false);
playPauseVideoButton.IsEnabled = true;
//we are done re-winding
flagRewind = false;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
This works but it's skipping frames, I tried using the speedration on a button click event like this:
private void slowPlayVideoButton_Click(object sender, RoutedEventArgs e)
{
playVideoMediaElement.SpeedRatio = (double)-1;
}
but this just stops (freezes) the video. How can I use the speed ratio to rewind the video smoothly? #Thanks!