how can i get duration of mp3 file in c# ?

All replies

  • The simplest one is with IWMPMedia interface (Duration attribute):

    using WMPLib;

    WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass(); IWMPMedia mediaInformation = wmp.newMedia(@"c:\test.mp3");

    • Edited by Castorix31 Monday, May 1, 2017 10:42 PM
    Monday, May 1, 2017 10:38 PM
  • Hi programmer10,

    Thank you for posting here.

    For your question, you could like to check the following link.

    In the article, it shows a simple example about get the list of mp3 and play songs, stop it.

    I hope this would be helpful.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, May 2, 2017 2:21 AM
  • Use an external library such as NAudio to do the hard work.
    NAudio is available at CodePlex.

    You can use it like this:

    Mp3FileReader reader = new Mp3FileReader("<YourMP3>.mp3");
    TimeSpan duration = reader.TotalTime;

    Tuesday, May 2, 2017 6:14 AM