以前是用xp (32位)系统,获取视频文件长度是通过调用Shell32.dll来读取文件信息得到的,最近换win7(32位)系统,编译以前的项目代码发现无法读取了,代码没有改动,拿到在xp下运行也不行了,可将代码在xp环境下编译却可以成功运行。附上代码
/// <summary>
/// 获取媒体文件播放时长
/// </summary>
/// <param name="path">媒体文件路径</param>
/// <returns></returns>
public 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;
}
}