0

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 ?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Welsh King
  • 3,178
  • 11
  • 38
  • 60

1 Answers1

0

I would try to read the ID3 tags in the MP3 files. This should allow you to get the data you need faster.

This library contains everything that you should need, but the question is if it's in the ID3 tag or if you need to scan the file (which takes time). http://sourceforge.net/projects/csid3lib/

This library might also be useful. http://sourceforge.net/projects/mpg123net/

eandersson
  • 25,781
  • 8
  • 89
  • 110