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 叶长种 阅读(...) 评论(...) 编辑 收藏