I have a winforms form in which I use a MediaElement. Everything is working (more or less) perfectly. The only thing is, after loading a media file (mp3) accessing NaturalDuration.TimeSpan.TotalSeconds throws an exception
InvalidOperatoinException: A TimeSpan property can not be returned for a duration value of automatic.
(Translated from german by myself)
How can I access the timespan property? There is no special setting used in all the examples I have found (ok, they seem to be WPF native…)
I am using VisualStudio Express .Net 4, C# on Windows 7.
Any hints?
You need to wait for
MediaOpenedevent to fire,NaturalDurationwill be available after that. To check if value is available, you can useNaturalDuration.HasTimeSpanproperty.