I have 20 mp3 chapter files in a list (per audio book) in a WPF c# that i need to parse to get the lengths of.
I'm currently looping around the following code which is hugely inefficient
MediaElement currentmp3 = new MediaElement();
currentmp3.UnloadedBehavior = MediaState.Manual;
currentmp3.LoadedBehavior = MediaState.Manual;
currentmp3.MediaOpened += new RoutedEventHandler(currentMp3_MediaOpened);
currentmp3.Source = new Uri(filename);
currentmp3.Play();
currentmp3.Pause();
currentmp3.UpdateLayout();
// if i dont add this it doesnt give the time.
Thread.Sleep(1000);
if (currentmp3.NaturalDuration.HasTimeSpan)
chapter.ChapterLength = currentmp3.NaturalDuration.TimeSpan;
currentmp3.Stop();
It takes up to 30 seconds to process.
Any suggestions on how to improve performance or anyone aware of any native / 3rd party utils that can do the same job quicker ?