0

I have below code to get mp3 file duration, but it return empty string. The file is located in drive c:

private string GetDuration(string FileFullPath)
{
    string duration = "";
    string fName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1);
    string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\"));
    Shell32.Shell shell = new Shell32.ShellClass();
    Shell32.Folder folder = shell.NameSpace(filePath);
    Shell32.FolderItem folderItem = folder.ParseName(fName);
    if (folderItem != null)
    {
        duration = folder.GetDetailsOf(folderItem, 21); //Only Empty for 21
    }
    folderItem = null;
    folder = null;
    shell = null;
    return duration;
}
3
  • 1
    Where is the 21 coming from? According to this documentation, only values -1 through 4 are documented: msdn.microsoft.com/en-us/library/windows/desktop/…
    – goric
    Feb 8, 2014 at 13:41
  • Look here. Audio is {64440490-4C8B-11D1-8B70-080036B11A03}, the length property is 3, unit is milliseconds. Feb 8, 2014 at 14:12
  • Thanks Hans, I added this string prop = (string)itm2.ExtendedProperty("{64440490-4C8B-11D1-8B70-080036B11A03} 3"); it gives the error: Unable to cast object of type 'System.UInt64' to type 'System.String'.
    – ARH
    Feb 9, 2014 at 4:55

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.