在 .Net 中使用 Taglib-sharp 2.0.4.0 编写 ArtWork 时遇到问题

发布于 2024-12-02 04:08:22 字数 244 浏览 1 评论 0原文

我在 MP3 文件中写入图稿时遇到问题。 我可以使用 Taglib-sharp 读取并显示 MP3 文件内的所有插图,但是当需要在 MP3 标签中插入超过 1 张图片(例如:封面和封底)时,我遇到了问题.如果这只是一件艺术品...我可以做到 有人可以给我扔骨头,并告诉我该怎么做吗? (vb.net 会很棒,但 C# 也能做到这一点)。

又一个请求...并删除 mp3 标签内的图像?有人可以给我一个关于如何做到这一点的例子吗?

感谢您的帮助

I'm having trouble with writing artwork in an MP3 File.
I'm able to read and display all the artwork inside the MP3 file, using Taglib-sharp, but when it comes to insert more than 1 Picture (ex:FrontCover and BackCover) in the MP3 tag, i'm having problems with that.If it's just one Artwork... i can do it
Can someone please throw me bone, and show me how to do it?? (vb.net would be great but C# also do the trick).

One more request... and deleting the image inside the mp3 tag?? Can someone please give me an example on how to do it also.

Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

—━☆沉默づ 2024-12-09 04:08:22

我遇到了与 Bobby Bhamra 相同的问题。我发现 iTunes 讨厌 UTF-16,这就是问题所在。

targetMp3File = TagLib.File.Create(...);

// define picture
TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
pic.TextEncoding = TagLib.StringType.Latin1;
pic.MimeType     = System.Net.Mime.MediaTypeNames.Image.Jpeg;
pic.Type         = TagLib.PictureType.FrontCover;
pic.Data         = TagLib.ByteVector.FromPath(...);

// save picture to file
targetMp3File.Tag.Pictures = new TagLib.IPicture[1] { pic };    
targetMp3File.Save();

所以本质上整个事情都在 pic.TextEncoding 行中。另外,我通过 .NET 常量分配了 Mime 类型。

因此,不需要 TagLib.PictureType.Other 或使用描述的解决方法。我的解决方案的唯一缺点是它仅适用于 MP3 文件。

I came across the same problem as Bobby Bhamra. I found that iTunes hates UTF-16 and that's what's the problem there.

targetMp3File = TagLib.File.Create(...);

// define picture
TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
pic.TextEncoding = TagLib.StringType.Latin1;
pic.MimeType     = System.Net.Mime.MediaTypeNames.Image.Jpeg;
pic.Type         = TagLib.PictureType.FrontCover;
pic.Data         = TagLib.ByteVector.FromPath(...);

// save picture to file
targetMp3File.Tag.Pictures = new TagLib.IPicture[1] { pic };    
targetMp3File.Save();

So essentially the whole thing is in the pic.TextEncoding line. Additionally i assigned the Mime Type through the .NET constant.

As a result there is no need for TagLib.PictureType.Other or the workaround using the Description. The only drawback on my solution is that it will only work correctly for MP3 files.

萧瑟寒风 2024-12-09 04:08:22

您如何插入和删除图像?你能发布一些代码吗?

所有标签都使用 IPicture 接口以及 Tag.Pictures getter 和 setter 来工作。修改 Tag.Pictures 数组的内容不会对文件产生任何影响,因此修改现有列表涉及获取当前值、对其进行操作,然后将其设置回来。只需设置或清除图片就更容易。

您可以使用以下方法将文件设置为具有单个图像:

IPicture pictures = new IPicture[1];
pictures[0] = new Picture("path/to/picture.jpg");
file.Tag.Pictures = pictures;

您可以使用以下方法从标签中删除所有图像:

file.Tag.Pictures = new IPicture[0];
file.Save();

操作或更复杂,但遵循相同的思路。如果 Tag.Pictures 是 IEnumerable 而不是数组,那就更好了,但已经完成了。

下面是一个从命令行参数设置图像的示例程序: https: //github.com/mono/taglib-sharp/blob/master/examples/SetPictures.cs

How are you inserting and removing images? Can you post some code?

All tags work using the IPicture interface and the Tag.Pictures getter and setter. Modifying the contents of the Tag.Pictures array will have no effect on the file so modifying the existing list involves getting the current value, maniplating it, and then setting it back. Simply setting or clearing the picture is easier.

You can set the file to have a single image with:

IPicture pictures = new IPicture[1];
pictures[0] = new Picture("path/to/picture.jpg");
file.Tag.Pictures = pictures;

You can remove all images from a tag with the following:

file.Tag.Pictures = new IPicture[0];
file.Save();

Manipulation or more complex but follows the same lines of thinking. It would have been better if Tag.Pictures was an IEnumerable instead of an array, but what's done is done.

Here's an example program that sets images from the command line arguments: https://github.com/mono/taglib-sharp/blob/master/examples/SetPictures.cs

不忘初心 2024-12-09 04:08:22

我在 MP3 标记应用程序中使用以下 taglib-sharp 代码。如果不设置“mime”和“类型”,即使 Windows/WMP 正确显示了该图稿,我也无法在 iTunes 中显示该图稿,随后又在我的 iPod 上显示该图稿。

TagLib.File targetFileMp3Tag = TagLib.File.Create(...);

Picture picture = new Picture();
picture.Type = PictureType.Other;
picture.MimeType = "image/jpeg";
picture.Description = "Cover";        
picture.Data = ByteVector.FromStream(...);

targetFileMp3Tag.Tag.Pictures = new IPicture[1] { picture };
targetFileMp3Tag.save()

I'm using the following taglib-sharp code in my MP3 tagging app. Without setting the 'mime' and 'type' I was unable to get the Artwork displaying in ITunes and subsequently on my Ipod even though Windows/WMP was correctly displaying it.

TagLib.File targetFileMp3Tag = TagLib.File.Create(...);

Picture picture = new Picture();
picture.Type = PictureType.Other;
picture.MimeType = "image/jpeg";
picture.Description = "Cover";        
picture.Data = ByteVector.FromStream(...);

targetFileMp3Tag.Tag.Pictures = new IPicture[1] { picture };
targetFileMp3Tag.save()

hth

意中人 2024-12-09 04:08:22

我使用的是 Taglib 版本 2.1.0.0,到目前为止,还没有该版本的文档。
所以我必须来这里搜索所有答案才能找到真正有效的东西
有了这个版本,这就是我想出的...

Private Sub SetTags()
    Me.Cursor = Cursors.WaitCursor

    'Set the version and force it.
    TagLib.Id3v2.Tag.DefaultVersion = 3
    TagLib.Id3v2.Tag.ForceDefaultVersion = True

    'Set all standard tags.
    strInput = Trim(txtMP3Input.Text)
    strTitle = Trim(txtTitle.Text)
    strArtist = Trim(txtArtist.Text)
    strAlbumArtist = Trim(txtAlbumArtist.Text)
    strAlbum = Trim(txtAlbum.Text)
    intYear = Convert.ToInt32(Val(cmbDate.SelectedItem))
    strGenre = cmbGenre.SelectedItem
    strComments = Trim(txtComment.Text)
    strArt = Trim(txtAlbumArt.Text)

    'Create a file (mp3)
    Dim fName As TagLib.File = TagLib.File.Create(strInput)

    'Set the Album art.
    Dim pics As Picture = New Picture(strArt)

    'Insert the standard tags.
    fName.Tag.Title = strTitle
    fName.Tag.Performers = New String() {strArtist}
    fName.Tag.AlbumArtists = New String() {strAlbumArtist}
    fName.Tag.Album = strAlbum
    fName.Tag.Year = intYear
    fName.Tag.Genres = New String() {strGenre}
    fName.Tag.Comment = strComments

    'Insert Album art and
    ' save to file and dispose.
    Dim picsFrame As New TagLib.Id3v2.AttachedPictureFrame(pics)
    picsFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg

    'set the type of picture (front cover)
    picsFrame.Type = TagLib.PictureType.FrontCover

    'Id3v2 allows more than one type of image, just one is needed here.
    Dim pictFrames() As TagLib.IPicture = {picsFrame}

    'set the pictures in the tag
    fName.Tag.Pictures = pictFrames

    fName.Save()
    fName.Dispose()

    Me.Cursor = Cursors.Default
    lblSuccess.Text = "Tags Set Successfully."
End Sub

我使用 Visual Studio 2012 安装了这个版本,并使用了菜单项
工具->库包管理器->包管理器控制台。在“PM>”提示 输入“Install-Package taglib” 这会将 Taglib-Sharp 包添加到您的应用程序中。它实际上是 Power Shell 的命令行实用程序。等待几秒钟,您就可以开始了。

I'm using Taglib version 2.1.0.0 and as of yet, there is no documentation for this version.
So I had to come here to search through all answer to find something that actually worked
with this version and this is what I came up with...

Private Sub SetTags()
    Me.Cursor = Cursors.WaitCursor

    'Set the version and force it.
    TagLib.Id3v2.Tag.DefaultVersion = 3
    TagLib.Id3v2.Tag.ForceDefaultVersion = True

    'Set all standard tags.
    strInput = Trim(txtMP3Input.Text)
    strTitle = Trim(txtTitle.Text)
    strArtist = Trim(txtArtist.Text)
    strAlbumArtist = Trim(txtAlbumArtist.Text)
    strAlbum = Trim(txtAlbum.Text)
    intYear = Convert.ToInt32(Val(cmbDate.SelectedItem))
    strGenre = cmbGenre.SelectedItem
    strComments = Trim(txtComment.Text)
    strArt = Trim(txtAlbumArt.Text)

    'Create a file (mp3)
    Dim fName As TagLib.File = TagLib.File.Create(strInput)

    'Set the Album art.
    Dim pics As Picture = New Picture(strArt)

    'Insert the standard tags.
    fName.Tag.Title = strTitle
    fName.Tag.Performers = New String() {strArtist}
    fName.Tag.AlbumArtists = New String() {strAlbumArtist}
    fName.Tag.Album = strAlbum
    fName.Tag.Year = intYear
    fName.Tag.Genres = New String() {strGenre}
    fName.Tag.Comment = strComments

    'Insert Album art and
    ' save to file and dispose.
    Dim picsFrame As New TagLib.Id3v2.AttachedPictureFrame(pics)
    picsFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg

    'set the type of picture (front cover)
    picsFrame.Type = TagLib.PictureType.FrontCover

    'Id3v2 allows more than one type of image, just one is needed here.
    Dim pictFrames() As TagLib.IPicture = {picsFrame}

    'set the pictures in the tag
    fName.Tag.Pictures = pictFrames

    fName.Save()
    fName.Dispose()

    Me.Cursor = Cursors.Default
    lblSuccess.Text = "Tags Set Successfully."
End Sub

I installed this version using Visual Studio 2012 threw use of the Menu Items
Tools->Library package Manager->Package manager Console. At the "PM>" prompt Type 'Install-Package taglib' This will add the Taglib-Sharp package to your application. It is actually a command line utility to the Power Shell. Wait a few seconds and you are ready to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文