C#中獲取MP3文件時長


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; 
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM