码迷,mamicode.com
首页 > Windows程序 > 详细

C#中获取MP3文件时长

时间:2018-05-28 16:05:19      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:时间   tor   ace   添加   reg   music   get   tail   expr   

1、添加引用:COM组件的Microsoft Shell Controls And Automation

2、添加命名空间:
    using Shell32;
    using System.Text.RegularExpressions;

3、

//获取mp3文件的歌曲时间长度
        private string GetMusicTime(string songPath)
        { 
            string dirName = System.IO.Path.GetDirectoryName(songPath);
            string SongName = System.IO.Path.GetFileName(songPath);//获得歌曲名称  
            // FileInfo fInfo = new FileInfo(songPath);
            ShellClass sh = new ShellClass();
            Folder dir = sh.NameSpace(dirName);
            FolderItem item = dir.ParseName(SongName);
            string s = Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;//获取歌曲时间
            return s; 
        }

 

C#中获取MP3文件时长

标签:时间   tor   ace   添加   reg   music   get   tail   expr   

原文地址:https://www.cnblogs.com/LY-HeroesRebor/p/9100250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!