Shell32获取视频信息

来源:互联网 发布:阿里云推荐码在哪里看 编辑:程序博客网 时间:2024/06/06 11:37
public static string GetMediaDuration(string path)
        {
            var width = 0;
            var height = 0;
            ShellClass sh = new ShellClass();
            Folder dir = sh.NameSpace(Path.GetDirectoryName(path));
            FolderItem item = dir.ParseName(Path.GetFileName(path));
            //字典存放属性名和属性值的键值关系对  
            Dictionary<string, string> Properties = new Dictionary<string, string>();
            int i = 0;
            while (true)
            {
                //获取属性名称  
                string key = dir.GetDetailsOf(null, i);
                if (string.IsNullOrEmpty(key))
                {
                    //当无属性可取时,推出循环  
                    break;
                }
                //获取属性值  
                string value = dir.GetDetailsOf(item, i);
                //保存属性  
                Properties.Add(key, value);
                if (key == "帧高度")
                {
                    height = Convert.ToInt32(value);
                }
                if (key == "帧宽度")
                {
                    width = Convert.ToInt32(value);
                }
                if (width != 0 && height != 0)
                {
                    return width + "," + height;
                }
                i++;
            }
            return "";
        }
0 0
原创粉丝点击