A
A
Artyom N2011-05-14 20:48:57
C++ / C#
Artyom N, 2011-05-14 20:48:57

How to update video frame in MediaElement? C# WPF?

Solution found. In XAML, you need to add a property to the element tag ScrubbingEnabled="True".
There is a media element, it contains an AVI video. By clicking on one button, the method is executed mediaElement.Play();, on the other - mediaElement.Pause();
There is a slider, the value of which is used to set the position of the video.

public DispatcherTimer _timer = new DispatcherTimer();
    public int waitnum = 3000;
    double TotalTime = 0;

    public MainWindow()
    {
        _timer.Interval = TimeSpan.FromSeconds(1);
        _timer.Tick += new EventHandler(_timer_Tick);
        InitializeComponent();
    }

    void _timer_Tick(object sender, EventArgs e)
    {
        double tPass = mediaElement1.Position.TotalSeconds;
        slider.Value = tPass;
    } 

    private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
    {
        slider.Maximum = mediaElement1.NaturalDuration.TimeSpan.TotalSeconds;
    }

    private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
    {
        _timer.Stop();
        TimeSpan ts = TimeSpan.FromSeconds(slider.Value);
        mediaElement1.Position = ts;
        textBox.Text = ts + " / " + mediaElement1.NaturalDuration;
        _timer.Start();
    }

    . . .

If you click on "pause" (in progress mediaElement.Pause();) and then move the slider, the position of the video changes, but the frame is not updated. How can I refresh a frame on pause?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artyom N, 2011-05-14
@nobr

ScrubbingEnabled="True"

E
ertaquo, 2011-05-14
@ertaquo

Try the InvalidateVisual method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question