TagLib usage to add Id3 headers to file

Thomas Salm tosate at gmail.com
Fri Apr 4 09:42:39 UTC 2014


Hi Jarno,

my application writes common tags like this:

bool MediaFile::WriteTags()
{
    TagLib::FileRef fileref(filename);

    if(!fileref.isNull())
    {
        TagLib::Tag *tag = fileref.tag();
        if(tag)
        {
            tag->setTitle(TagLib::String(tagData->Title()));
            tag->setArtist(TagLib::String(tagData->Artist()));
            tag->setAlbum(TagLib::String(tagData->Album()));
            tag->setComment(TagLib::String(tagData->Comment()));
            tag->setGenre(TagLib::String(tagData->Genre()));
            tag->setYear(tagData->Year());
            tag->setTrack(tagData->Track());
        }
        else
        {
            return false;
        }
        return fileref.save();
    }
    return false;
}

This works for every supported audio file format. As long as you don't want
to add format specific metadata (like cover pictures for instance), you
don't have to worry about property maps, frames etc.
I cannot reproduce the case that fileref.tag() returns a NULL pointer.
Even if my file is a text file with mp3 extension and not an actual audio
file, the method works and metadata information is written to the file.

Cheers,
Thomas


On Fri, Apr 4, 2014 at 9:58 AM, Jarno Lavikonmäki <lavikonm at gmail.com>wrote:

>
> Hi,
>
> some part of this tag lib that I do not yet understand
>
> the case here is to update metadata to file
>
> first , if I try
>
>  TagLib::FileRef f("mytestmp3.mp3");
>
> then f.tag() returns NULL;
>
> then I do it this way:
>
>  TagLib::MPEG::File mp3File("mytestmp3.mp3");
>
> first round, this mp3 files does not have ID3v2 or ID3v1
>
> so it goes to "else" branch and calls to to  create ID3v2Tag(true)
>
> and then calls
>
> mp3Tagv2->setArtist("setArtistField");
>
> and after that
> bool result = mp3File.save();
>
> ..
>
> then next round ..
>
> hasID3v2Tag() returns true
>
> but actual file in file system does not have metadata updated ,
>
> so what is the "documented" way , to use propertymaps or something else ?
>
> Thanks in advance
>
> br. Jarno
>
> _______________________________________________
> taglib-devel mailing list
> taglib-devel at kde.org
> https://mail.kde.org/mailman/listinfo/taglib-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/taglib-devel/attachments/20140404/b241c72f/attachment.html>


More information about the taglib-devel mailing list