我无法在 MP3 文件中编写图稿。我可以使用 Taglib-sharp 读取和显示 MP3 文件中的所有艺术品,但是当在 MP3 标签中插入超过 1 张图片(例如:FrontCover 和 BackCover)时,我遇到了问题.如果它只是一件艺术品...我可以做到有人可以给我扔骨头,并告诉我怎么做吗?(vb.net 会很棒,但 C# 也能做到这一点)。
再提出一个请求……并删除 mp3 标签内的图像??有人可以给我一个关于如何做到这一点的例子。
谢谢你的帮助
我无法在 MP3 文件中编写图稿。我可以使用 Taglib-sharp 读取和显示 MP3 文件中的所有艺术品,但是当在 MP3 标签中插入超过 1 张图片(例如:FrontCover 和 BackCover)时,我遇到了问题.如果它只是一件艺术品...我可以做到有人可以给我扔骨头,并告诉我怎么做吗?(vb.net 会很棒,但 C# 也能做到这一点)。
再提出一个请求……并删除 mp3 标签内的图像??有人可以给我一个关于如何做到这一点的例子。
谢谢你的帮助
您如何插入和删除图像?你能发布一些代码吗?
所有标签都使用 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
我遇到了与 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 文件。
我在我的 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()
hth
我使用的是 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 的命令行实用程序。等待几秒钟,您就可以开始了。