Search code examples
c++qtaudio-playerid3

How can I implement IDv3 tags in a Qt Program?


I just made a qt sound player, it can plays mp3 and other types of audio, but I want to make it more useful for reading the tracks name and maybe the text of the song, in a short future. For now the application only displays the name of the file.

What library should be implemented? I found some libraries but they are dated and no more supported


Solution

  • There's a few different libraries for reading information on sound files, you can try id3lib

    The code is easy to read if you are okaysh with C++:

    #include <id3/tag.h>
    

    First you need to know what are the possible informatio that the library can give to you:

    void ShowKnownFrameInfo() {
         ID3_FrameInfo myFrameInfo;
        for (int cur = ID3FID_NOFRAME+1; cur < myFrameInfo.MaxFrameID(); cur ++)
        { 
         cout << "Short ID: " << myFrameInfo.ShortName(ID3_FrameID(cur)) <<
             " Long ID: " << myFrameInfo.LongName(ID3_FrameID(cur)) <<
             " Desription: " << myFrameInfo.Description(ID3_FrameID(cur)) << endl;
        }
     }
    

    Use that information in the code below to access the information and use it anywhere

    void readTags(const std::string& musicFile) {
        ID3_Tag myTag(musicFile);
        QScopedPtr<ID3_Tag::Iterator> iter(myTag.CreateIterator());
        ID3_Frame* myFrame = NULL;
        while (NULL != (myFrame = iter->GetNext()))
        {
            myFrame->Get("Key", 1024);
        }
    }