How do I use taglib-sharp?

随声附和 提交于 2019-12-21 11:03:35

问题


I'm having a bunch of troubles with this library (obviously because I'm a newbie). I'm using Microsoft Visual Studio 2015.

First of all I have absolutely no idea on how to add this library to my project. I didn't find anything helpful on Google, either.

And second, I've found two different libraries - taglib-sharp-master and taglib-sharp-2.1.0.0-windows. Which one should I use?


回答1:


There are a few things you'll want to do in order to get taglib-sharp working in your project.

Firstly, you need to stick to a particular project type. Next, you are to install the suitable library version for that project. Next, you can use the library as you wish to. I shall also provide a minimal example to get you started and a link to a bunch of examples which you might find of help.

Choosing the correct version of TagLib:

There's some ambiguity in your question as you have tagged it with both c++ and c#. If you want to use c++ in your project, then your best bet is to use the taglib library. Note: Not the 'sharp' version.

However, almost the entire question and its title speaks of taglib-sharp. Given that, I shall presume that you are using c# for your project. Accordingly, your project is a .NET C# project. You can obviate the quandary over selecting the project type. Any of the project types (WinForms, WPF, Console Application will work just fine as taglib-sharp is just an off-screen library.

And also, FYI, both taglib-sharp-master and taglib-sharp-2.1.0.0-windows are essentially the same stuff. The former is probably the latest version since the latter specifies a definite version 2.1.0.0. But again, 2.1.0.0 has long been the latest version of taglib-sharp. So, use either, and you should be fine.

Installing TagLib-Sharp a.k.a. TagLib#:

Next up, you must install TagLib-Sharp to your project. There are a few ways to do so:

  • Install it via Nuget
  • Add a reference to the binary

♦  Installing via Nuget:

This is probably the recommended way of installing any library/component in Visual Studio. Head over to the Nuget Package Manager Console. Once there, type in:

Install-Package taglib

Nuget Package link: Taglib-Sharp.

and press ENTER.

For more information on the Nuget Package Manager Console, how to open it and use it, visit this link.

You can also add it with the help of the Nuget Package Manager (GUI). Open the Package Manager and search for "taglib-sharp". Install the appropriate package that shows in the search results.

For more information on the Nuget Package Manager, how to open and use it, visit this link.

♦  Downloading the binary and adding a reference to it directly:

You can download the latest version of the taglib-sharp binaries here. The download is a .zip archive. Unzip the file.

In the unzipped folder, head over to \Libraries. There, find the taglib-sharp.dll file. Keep a note of where the file is located.

Next, in Visual Studio, go to Project > Add Reference.

There, in the left panel, select Browse. Now in the dialog buttons section, click browse and locate the .dll file you extracted from the .zip archive. Make sure the CheckBox next to it is checked:

Click OK.

Now you are all set to use TagLib-Sharp.

Using TagLib-Sharp (Examples):

The minimal example of using the library would be opening a file and editing its Title property and retrieving the Year property:

var file = TagLib.File.Create("<yourFile.mp3>"); // Change file path accordingly.

file.Tag.Title = "My Own Song";

var year = file.Tag.Year;

// Save Changes:
file.Save();

You can also find a similar example here to get your started.

More examples:

  • Set Bitmap as cover art for MP3
  • https://github.com/mono/taglib-sharp/tree/master/examples
  • https://www.codeproject.com/messages/3009089/extracting-id3-albumart-with-taglib-sharp.aspx

If you have further queries, feel free to ask in the comments below. And also, if the question deserves a separate thread, word it properly and ask it here on Stack Overflow itself.

Hope this answer helps. :)



来源:https://stackoverflow.com/questions/40826094/how-do-i-use-taglib-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!