It is necessary to display the time of the tracks. It turns out to do, if for example only mp3. But there may be other formats in the playlist, such as WAV and Vorbis. How can you implement automatic switching between types to display time for any of the two file types. Now done as follows:

private static void Main(string[] args) { try { foreach (var file in GetFileInfo()) { Mp3FileReader reader = new Mp3FileReader(file.FullName); WaveFileReader s; //?? TimeSpan duration = reader.TotalTime; Console.WriteLine(duration); } } catch (Exception e) { Console.WriteLine(e); } Console.ReadKey(); } public static IList<FileInfo> GetFileInfo() { DirectoryInfo directories = new DirectoryInfo("D:\\TestAudio"); var extensions = new string[] { "*.mp3", "*.mp4", "*.wav", "*.wma", "*.ogg", "*.spx" }; var files = extensions.SelectMany(ext => directories.GetFiles(ext, SearchOption.AllDirectories)); return files.ToList(); } 

When it comes to WAV files, it displays an exception accordingly.

enter image description here

    1 answer 1

    Use AudioFileReader:

     AudioFileReader reader = new AudioFileReader(path); 

    He should be able to output the length for all supported file types (this includes WAV and MP3, but not OGG Vorbis, unless a codec is installed for it).

    • Fine! Thank you very much! The only tracks with a bitrade below 100 kb / s throw an exception. - JDo pm