C# 获取mp3文件的歌曲时间长度

添加命名空间:
    using Shell32;
    using System.Text.RegularExpressions;
添加引用:COM组件的Microsoft Shell Controls And Automation

string dirName = Path.GetDirectoryName(SongPath);
SongName = Path.GetFileName(SongPath);//获得歌曲名称
FileInfo fInfo = new FileInfo(SongPath);
ShellClass sh = new ShellClass();
Folder dir = sh.NameSpace(dirName);
FolderItem item = dir.ParseName(SongName);
SongTime = Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;//获取歌曲时间
 
posted @ 2017-06-30 18:03  代码沉思者  阅读(3896)  评论(0编辑  收藏  举报