Checking Tag Availability

Jim jmartin92 at comcast.net
Fri Oct 8 22:49:15 CEST 2010


Roustam Ghizdatov wrote:
> hello,
> 
> first of all, i'd like to express my deepest gratitude to the
> developers of TagLib. i'm trying to use it in my application and have
> a question for that matter.
> 
> TagLib::MPEG::File mpegFile(fileName, true, TagLib::AudioProperties::Accurate);
> if (mpegFile.ID3v2Tag()) { ... }
> 
> the condition in the above code always returns true even if there's no
> ID3v2 tag. so, i have to check FrameList instead:
> 
> TagLib::ID3v2::FrameList frameList = mpegFile.ID3v2Tag()->frameList();
> if (!frameList.isEmpty()) { ... }
> 
> is this a feature or a bug?
> 
> thank you,
> 
> Roustam


Hi.

You are right that you cannot simply check the result of MPEG::File.ID3v2Tag() 
even if the create flag is set to false.  This is because of a couple lines at 
the end of MPEG::File::read(), which is called when you open an MPEG file. 
These lines say:

   // Make sure that we have our default tag types available.

   ID3v2Tag(true);
   ID3v1Tag(true);

so it creates an empty ID3v1 and v2 tag whenever you open a file.  I'm not sure 
of the reasons for this code being added but it means it is by design, not a bug.

However, you can use ID3v2::Tag::isEmpty(), which really does the same thing as 
your code.

I hope this helps.

Jim




More information about the taglib-devel mailing list