Loading
0

c#获取歌曲、视频的总长度

技术小学生微信公众号
腾讯云服务器大促销。
华为服务器
c#获取歌曲、视频的总长度

//获取视频的长度
        public int GetVideoLength(string SongPath)
        {
            string[] strs = new string[4];
            //string SongPath = @"D:\蔡依林、陶喆 - 今天你要嫁给我 (吉特巴版).mp3";
            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);
            //string SongTime = Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;//获取歌曲时间  
            string fileName = dir.GetDetailsOf(item, 0); //文件名
            string fileSize = dir.GetDetailsOf(item, 1); //大小
            string fileLength = dir.GetDetailsOf(item, 27); //时间
            strs[0] = fileName; //文件名
            strs[1] = dirName; //文件夹
            strs[2] = fileSize; //大小
            strs[3] = fileLength; //持续时间
            return songLengthTo0Sec(strs[3]);
        }


        private int songLengthTo0Sec(string songLength)
        {
            string[] arr = songLength.Split(':');
            int ret = Convert.ToInt32(arr[1]) * 60 + Convert.ToInt32(arr[2]);
            return ret;
        }

歌曲长度

private string songLengthToMS(string songLength)
        {
            string[] arr = songLength.Split(':');
            string ms = (Convert.ToInt16(arr[0]) * 3600000 + Convert.ToInt16(arr[1]) * 60000 + Convert.ToInt16(arr[2]) * 1000).ToString();
            return ms;
        }

        private string songLengthTo0Min0Sec(string songLength)
        {
            string[] arr = songLength.Split(':');
            string str = arr[1] + "分" + arr[2] + "秒";
            return str;
        }
 
        private int songLengthTo0Sec(string songLength)
        {
            string[] arr = songLength.Split(':');
            int ret = Convert.ToInt32(arr[1]) * 60 + Convert.ToInt32(arr[2]) ;
            return ret;
        }

        private void button17_Click(object sender, EventArgs e)
        {
            //string cmd = "ffmpeg -ss 00:00:06 -i " + "\"D:\\input.mp4\"" + " -f image2 " + "\"D:\\test.jpg\"";
            //string cmd = textBox10.Text;
            //FFmpegExeCmd(cmd);
        }

        //获取歌曲的长度信息
        public string[] GetSongInfo(string SongPath)
        {
            string[] strs = new string[4];
            //string SongPath = @"D:\蔡依林、陶喆 - 今天你要嫁给我 (吉特巴版).mp3";
            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);
            //string SongTime = Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;//获取歌曲时间  
            string fileName = dir.GetDetailsOf(item, 0); //文件名
            string fileSize = dir.GetDetailsOf(item, 1); //大小
            string fileLength = dir.GetDetailsOf(item, 27); //时间
            strs[0] = fileName; //文件名
            strs[1] = dirName; //文件夹
            strs[2] = fileSize; //大小
            strs[3] = fileLength; //持续时间
            //for (int i = 0; i <= 80; i++)
            //{
            //    Logrtb(dir.GetDetailsOf(item, i),richTextBox5);
            //}
            return strs;
        }




 
技术小学生微信公众号
华为服务器
腾讯云服务器大促销。

声明:站长码字很辛苦啊,转载时请保留本声明及附带文章链接:https://blog.tag.gg/showinfo-23-36059-0.html
亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?
上一篇:c#获取文件夹中的子文件
下一篇:c#字符串提取(获取两个字符串中间的字符串)