C# 查看/编辑 MP3 文件的 ID3 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/68283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 11:05:01  来源:igfitidea点击:

View/edit ID3 data for MP3 files

提问by Mag Roader

What's a quick and easy way to view and edit ID3 tags (artist, album, etc.) using C#?

使用 C# 查看和编辑 ID3 标签(艺术家、专辑等)的快速简便方法是什么?

采纳答案by Luke

Thirding TagLib Sharp.

第三个TagLib Sharp

TagLib.File f = TagLib.File.Create(path);
f.Tag.Album = "New Album Title";
f.Save();

回答by tslocum

TagLib Sharphas support for reading ID3 tags.

TagLib Sharp支持读取 ID3 标签。

回答by mmcdole

TagLib Sharpis pretty popular.

TagLib Sharp非常受欢迎。

As a side note, if you wanted to take a quick and dirty peek at doing it yourself.. here is a C# snippet I found to read an mp3's tag info.

作为旁注,如果您想快速而肮脏地偷看自己做的事情..这是我发现的一个 C# 片段,用于读取 mp3 的标签信息。

class MusicID3Tag

{

    public byte[] TAGID = new byte[3];      //  3
    public byte[] Title = new byte[30];     //  30
    public byte[] Artist = new byte[30];    //  30 
    public byte[] Album = new byte[30];     //  30 
    public byte[] Year = new byte[4];       //  4 
    public byte[] Comment = new byte[30];   //  30 
    public byte[] Genre = new byte[1];      //  1

}

string filePath = @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music1105.mp3";

        using (FileStream fs = File.OpenRead(filePath))
        {
            if (fs.Length >= 128)
            {
                MusicID3Tag tag = new MusicID3Tag();
                fs.Seek(-128, SeekOrigin.End);
                fs.Read(tag.TAGID, 0, tag.TAGID.Length);
                fs.Read(tag.Title, 0, tag.Title.Length);
                fs.Read(tag.Artist, 0, tag.Artist.Length);
                fs.Read(tag.Album, 0, tag.Album.Length);
                fs.Read(tag.Year, 0, tag.Year.Length);
                fs.Read(tag.Comment, 0, tag.Comment.Length);
                fs.Read(tag.Genre, 0, tag.Genre.Length);
                string theTAGID = Encoding.Default.GetString(tag.TAGID);

                if (theTAGID.Equals("TAG"))
                {
                    string Title = Encoding.Default.GetString(tag.Title);
                    string Artist = Encoding.Default.GetString(tag.Artist);
                    string Album = Encoding.Default.GetString(tag.Album);
                    string Year = Encoding.Default.GetString(tag.Year);
                    string Comment = Encoding.Default.GetString(tag.Comment);
                    string Genre = Encoding.Default.GetString(tag.Genre);

                    Console.WriteLine(Title);
                    Console.WriteLine(Artist);
                    Console.WriteLine(Album);
                    Console.WriteLine(Year);
                    Console.WriteLine(Comment);
                    Console.WriteLine(Genre);
                    Console.WriteLine();
                }
            }
        }

回答by Matt

UltraID3Lib...

UltraID3Lib...

Be aware that UltraID3Lib is no longer officially available, and thus no longer maintained. See comments below for the link to a Github project that includes this library

请注意,UltraID3Lib 不再正式可用,因此不再维护。有关包含此库的 Github 项目的链接,请参阅下面的评论

//using HundredMilesSoftware.UltraID3Lib;
UltraID3 u = new UltraID3();
u.Read(@"C:\mp3\song.mp3");
//view
Console.WriteLine(u.Artist);
//edit
u.Artist = "New Artist";
u.Write();

回答by Daniel Mo?mondor

I wrapped mp3 decoder library and made it available for .net developers. You can find it here:

我包装了 mp3 解码器库,并将其提供给 .net 开发人员。你可以在这里找到它:

http://sourceforge.net/projects/mpg123net/

http://sourceforge.net/projects/mpg123net/

Included are the samples to convert mp3 file to PCM, and read ID3 tags.

包括将 mp3 文件转换为 PCM 和读取 ID3 标签的示例。

回答by 0x8BADF00D

ID3.NETimplemented ID3v1.x and ID3v2.3 and supports read/write operations on the ID3 section in MP3 files. There's also a NuGet packageavailable.

ID3.NET实现了 ID3v1.x 和 ID3v2.3,并支持对 MP3 文件中 ID3 部分的读/写操作。还有一个NuGet 包可用。