zoukankan      html  css  js  c++  java
  • C#获取视频文件播放长度

    添加引用SHELL32.DLL

    根据网上代码改编

        public static class GetVideoLength
        {
            public static string GetMediaTimeLen(string path)
            {
                try
                {
                    Shell32.Shell shell = new Shell32.Shell();
                    //文件路径               
                    Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
                    //文件名称             
                    Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 2));
                    if (Environment.OSVersion.Version.Major >= 6)
                    { 
                        return folder.GetDetailsOf(folderitem, 27);
                    }
                    else 
                    { 
                        return folder.GetDetailsOf(folderitem, 21);
                    }
                }
                catch (Exception ex) { return null; }
            }
    
            public static int GetMediaTimeLenSecond(string path)
            {
                try
                {
                    Shell32.Shell shell = new Shell32.Shell();
                    //文件路径               
                    Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
                    //文件名称             
                    Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 2));
                    string len;
                    if (Environment.OSVersion.Version.Major >= 6)
                    {
                        len =  folder.GetDetailsOf(folderitem, 27);
                    }
                    else
                    {
                        len = folder.GetDetailsOf(folderitem, 21);                    
                    }
    
                    string[] str = len.Split(new char[] { ':' });
                    int sum = 0;
                    sum = int.Parse(str[0]) * 60 * 60 + int.Parse(str[1]) * 60 + int.Parse(str[2]);
    
                    return sum;
                }
                catch (Exception ex) { return 0; }
            }
        }
  • 相关阅读:
    lLinux 下 Stress 压力测试工具
    zabbix 微信告警配置
    spark Intellij IDEA开发环境搭建
    Spark调优与调试
    在centos 6.5 x64中安装 spark-1.5.1
    二叉树的各种遍历算法
    ServletResponse的一些知识点
    UVA 10303 How Many Trees? (catlan)
    UVA 10183 How Many Fibs?
    UVA 10471 Gift Exchanging
  • 原文地址:https://www.cnblogs.com/futao/p/2528724.html
Copyright © 2011-2022 走看看