I would like to use TagLib to read/write coverart especially for mp3 AND ogg files, but I couldn\'t find any examples. Could someone point me to some examples? Where should I lo
Ogg Vorbis tags are text-only (and as such don't support cover art). For MP3s, this is somewhat cleaner than the other solution suggested:
using namespace TagLib;
struct Image
{
Image(const String &m = String(), const ByteVector &d = ByteVector()) :
mimeType(m), data(d) {}
String mimeType;
ByteVector data;
};
static Image getImage(const ID3v2::Tag *tag)
{
ID3v2::FrameList frames = tag->frameList("APIC");
if(frames.isEmpty())
{
return Image();
}
ID3v2::AttachedPictureFrame *frame =
static_cast(frames.front());
return Image(frame->mimeType(), frame->picture());
}
static void setImage(ID3v2::Tag *tag, const Image &image)
{
ID3v2::FrameList frames = tag->frameList("APIC");
ID3v2::AttachedPictureFrame *frame = 0;
if(frames.isEmpty())
{
frame = new TagLib::ID3v2::AttachedPictureFrame;
tag->addFrame(frame);
}
else
{
frame = static_cast(frames.front());
}
frame->setPicture(image.data);
frame->setMimeType(image.mimeType);
}