26 Mayıs 2012 Cumartesi

How to get duration of an audio file in c# ?

To contact us Click HERE
We can get the duration of an audio or video file by using the “Shell32” namespace in Visual Studio Dot Net. For that we need to add the reference of “Interop.Shell32.dll” in to our project. And follow the given method in below. By calling the following method with the parameter of full path of file name which might be an audio file or video file we can get the duration of that file.

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);
}
folderItem = null;
folder = null;
shell = null;
return duration;
}

Hence we can get the duration of given file.

…S.VinothkumaR.

Hiç yorum yok:

Yorum Gönder