How to read and write ID3 tags to an MP3 in C#?
Taglib# is the best. It's direct port of the TagLib C library to C#.
To install TagLib#, run the following command in the Package Manager Console in Visual Studio.
PM> Install-Package taglib
The NuGet distribution of taglib-sharp can be found at http://nuget.org/packages/taglib.
The official source code repository is at https://github.com/mono/taglib-sharp.
Here's an example using the library:
TagLib.File file = TagLib.File.Create("mysong.mp3");
String title = file.Tag.Title;
String album = file.Tag.Album;
String length = file.Properties.Duration.ToString();
View/edit ID3 data for MP3 files
Thirding TagLib Sharp.
TagLib.File f = TagLib.File.Create(path);
f.Tag.Album = "New Album Title";
f.Save();
How do I read mp3 tags?
Keep in mind that not all mp3 files will have tags. There is nothing in the mp3 format that supports tag metadata. The most accepted formats for tags are de-facto formats, most notably ID3v1, ID3v2, and APEv2. These tags, if present, are normally embedded at the beginning or end of the file separate from the mp3 header and frame data.
In other words, if a library fails to read tags from a given mp3 file, it may well be that there are none, which is not the fault of the library.
Reading ID3 tags from the web with C#
You would have to download the file locally and then run taglib against the local version.
WebClient Client = new WebClient ();
Client.DownloadFile("http://myserver.com/indie/band1.mp3", "band1.mp3");
you could use the TagLib.File.IFileAbstraction, but I find downloading the file locally to be a lot simpler.
Write Picture to mp3 File ID3.NET Windows Store Apps
stream.WriteTag(tag, 1, 0, WriteConflictAction.Replace);
1
represents the major and 0
the minor ID3 version. Since media types such as pictures/images are not implemented in version 1, you'll need to use at least version 2. (2.3 being the most popular version used in ID3 tagging libraries and 2.4 being the newest version released in 2000)
stream.WriteTag(tag, 2, 3, WriteConflictAction.Replace);
will resolve your issue. Please note that you also need to create an Idv23Tag
when applying the code above:
var tag = new Id3v23Tag();
See http://en.wikipedia.org/wiki/ID3 for more information.
Related Topics
How to Make Chrome Headless After I Login Manually
Automatically Start a Windows Service on Install
The Name '...' Does Not Exist in the Current Context
Casting Object to Int Throws Invalidcastexception in C#
Run Selenium Tests in Multiple Browsers One After Another from C# Nunit
How to I Apply Filter While Paginating in ASP.NET MVC and Entity Framework
How to Remove Item from Querystring in ASP.NET Using C#
Post-Increment Within a Self-Assignment
How to Solve Disturbance in My Bot in C#
C# Gui Refresh and Async Serial Port Communication
How to Reduce Memory Consumption of PDFptable with Many Cells
How to Auto Resize and Adjust Form Controls with Change in Resolution
How to Get a List<String> Collection of Values from App.Config in Wpf
How to Make My Windows Form App Snap to Screen Edges
JSONconvert.Serializeobject Always Return {} in Xamarinforms