Search code examples
c#wpfmedia-player

WPF Media Player natural duration


If I use:

string Text = mediaPlayer.NaturalDuration.ToString();

I get everytime "automatic" as text. Is it the correct way to get media duration? What I do incorrect? Do you know any diferent solution? I want to get text in min:seconds pattern ideally.


Solution

  • If the NaturalDuration has a value of automatic, then the MediaOpened event has not been raised.

    Once the event is raised, you can get the duration like:

    string Text = mediaPlayer.NaturalDuration.TimeSpan.ToString(@"mm\:ss");