I need to create a M3U playlist of mp3 songs.
Is there any way to read the duration attribute of MP3 files?
I need to create a M3U playlist of mp3 songs.
Is there any way to read the duration attribute of MP3 files?
Don't reinvent the wheel. Use an external library such as NAudio to do the hard work.
You can use it like this:
Mp3FileReader reader = new Mp3FileReader("<YourMP3>.mp3");
TimeSpan duration = reader.TotalTime;
Of course, an alternative would be this answer.
To use the Mp3FileReader
class, you must add using NAudio.Wave;
to your file.
Thanks everyone for help.
I tryed using TagLib and it works fine.
TagLib.File f = TagLib.File.Create(<pathToFile>, TagLib.ReadStyle.Average);
var duration = (int)f.Properties.Duration.TotalSeconds;