I have build a WPF application where users can drag and drop MP3 files onto a listbox. I need a way to calculate the total duration of the playlist.
Any libraries I should use? Or is it possible using only the .NET framework?
I have build a WPF application where users can drag and drop MP3 files onto a listbox. I need a way to calculate the total duration of the playlist.
Any libraries I should use? Or is it possible using only the .NET framework?
I ended up writing my own for this purpose a few years back. You can write an effective one client-side using flash. The key points that I remember are:
Edit: I realize you wanted to do this with .Net, but it may actually be more useful to know client side before you upload the file to the server, as if you wish to impose limits on file length, you can do that much earlier in the process.
[my own solution]
I've added a second mediaelement control which I use to open each mp3 file in the listbox and get it's NaturalDuration. Open and close each file in the list and make a sum of all the values.
As stated by others, the mp3 headers aren't accurate. The mediaelement provides the correct duration.
It's probably not the fastest method but in my case the simplest (it does not rely on other libraries).
I wrapped mp3 decoder library and made it available for .net developers. You can find it here:
http://sourceforge.net/projects/mpg123net/
Included are the samples to convert mp3 file to PCM, and read ID3 tags.
I guess that it can be used to properly calculate mp3 file duration.