hi, can taglib_c read or write picture data in mp3 file 's tag
jon bird
news at onastick.clara.co.uk
Sun Oct 11 14:10:59 CEST 2009
In article <1255085970.3477.14.camel at zhangze-desktop>, zhangze
<zhangze at redflag-linux.com> writes
>the music player is developed in C language, so i must use C bindings
>of
>taglib, thereis nothing about picture reading and writing
>in /usr/include/taglib_c.h header file.
If you're conversant in 'C' and you're prepared to persevere then you
should be able to cobble together a bit of C++ code and put a 'C'
wrapper around it (just 'extern 'C' it). I'm not that familiar with the
intricacies of C++ and it was a bit painful going but I've managed to do
just that in order to interface it back to my main C code. If it helps,
this is the basis of the code I use to extract cover art:
static const char *IdPicture = "APIC" ;
// get raw bitmap (rgb) of attached cover art image held in tag
DLLEXPORT void *AttachedCoverArtFromId3Tag ( const char *FileName, int
*Width, int *Height )
{
MPEG::File TagFile( FileName, false ) ;
ID3v2::Tag *id3v2tag = TagFile.ID3v2Tag();
TagLib::ID3v2::FrameList Frame ;
TagLib::ID3v2::AttachedPictureFrame *PicFrame ;
void *RetImage = NULL, *SrcImage ;
unsigned long Size ;
if ( id3v2tag )
{
// picture frame
Frame = id3v2tag->frameListMap()[IdPicture] ;
if (!Frame.isEmpty() )
{
// find cover art
for(ID3v2::FrameList::ConstIterator it = Frame.begin(); it !=
Frame.end(); ++it)
{
PicFrame = (ID3v2::AttachedPictureFrame *)(*it) ;
if ( PicFrame->type() ==
TagLib::ID3v2::AttachedPictureFrame::FrontCover )
{
// extract image (in it's compressed form)
Size = PicFrame->picture().size() ;
SrcImage = malloc ( Size ) ;
if ( SrcImage )
{
memcpy ( SrcImage, PicFrame->picture().data(), Size ) ;
// pass image to appropriate decompressor
if ( !_stricmp ( PicFrame->mimeType().toCString(),
"image/jpeg" ) )
RetImage = JpegImageToRaw ( SrcImage, Size, Width, Height
) ;
else if ( !_stricmp ( PicFrame->mimeType().toCString(),
"image/png" ) )
RetImage = PngImageToRaw ( SrcImage, Size, Width, Height )
;
free ( SrcImage ) ;
}
if ( RetImage )
break ;
}
}
}
}
return RetImage ;
}
Any C++ purists out there, feel free to point and laugh....
Rgs,
Jon.
--
== jon bird - software engineer
== <reply to address _may_ be invalid, real mail below>
== <reduce rsi, stop using the shift key>
== posted as: news 'at' onastick 'dot' clara.co.uk
More information about the taglib-devel
mailing list