小编Lau*_*ngs的帖子

C# TagLib 设置 Mp3 专辑封面

我有一个 mp3 文件,我想向其中添加专辑封面。艺术作品已保存到临时文件夹中,我已检查过它,它就在那里并且是 jpeg。这是我给出的代码:

        public void AddMp3Tags()
        {
            TagLib.File file = TagLib.File.Create(OutputPath + OutputName + "." + Format);
            SetAlbumArt(Art, file);
            file.Tag.Title = SongTitle;
            file.Tag.Performers = Artists.Split(',');
            file.Tag.Album = Album;           
            file.Tag.Track = (uint)TrackNumber;
            file.Tag.Year = (uint)Convert.ToInt32(Regex.Match(Year, @"(\d)(\d)(\d)(\d)").Value);            
            file.Save();
        }

        public void SetAlbumArt(string url, TagLib.File file)
        {     
            string path = string.Format(@"{0}temp\{1}.jpg", OutputPath, Guid.NewGuid().ToString());
            using (WebClient client = new WebClient())
            {

                client.DownloadFile(new Uri(url), path);
            }


            TagLib.Picture pic = new TagLib.Picture
            {
                Type = TagLib.PictureType.FrontCover,
                Description = "Cover",
                MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg
            };
            MemoryStream ms …
Run Code Online (Sandbox Code Playgroud)

c# mp3 id3 cover taglib

4
推荐指数
1
解决办法
3427
查看次数

标签 统计

c# ×1

cover ×1

id3 ×1

mp3 ×1

taglib ×1