添加一个类
public class FormatConverter
{
public static string GetMediaTimeLen(string path)
{
try
{
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
return folder.GetDetailsOf(folderitem, 21);
}
catch (Exception ex)
{
return null;
}
}
public static string GetMediaTimes(string SongPath)
{
string dirName = Path.GetDirectoryName(SongPath);
string SongName = Path.GetFileName(SongPath);
FileInfo fInfo = new FileInfo(SongPath);
ShellClass sh = new ShellClass();
Folder dir = sh.NameSpace(dirName);
FolderItem item = dir.ParseName(SongName);
return Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;
}
}
调用
string time = FormatConverter.GetMediaTimes(filefullname);
|