PDA

View Full Version : MP3 Tags



Geysser
22nd January 2010, 01:49
Hi to everyone!
I would need some advice on reading mp3 tags from mp3 files (ID3v1 for now-you have to walk before you fly!) but I can't find help anywhere! I'm fairly new to bot Qt and C++ but I consider myself a pretty quick learner in programming languages. I've been programming in VB.NET for the past three years, but now I see no option but to sharpen my teeth in C++ too!
The question is pretty obvious: how do I read MP3 Tags?
Here is the code for adding files in a tree widget (through an action):

void wndMain::on_actAddFiles_triggered()//Add files
{
QString music_location=QDesktopServices::storageLocation(Q DesktopServices::MusicLocation);
QStringList sFiles=QFileDialog::getOpenFileNames(this,tr("Add mp3 files..."),music_location,
"Mp3 files (*.mp3)");
//Check if something is selected
if (sFiles.isEmpty())
return;
//If yes, add them to the list
foreach (QString sFile,sFiles)
{
//setup an item
QTreeWidgetItem *item=new QTreeWidgetItem(ui->trwLibrary);
QFileInfo f(sFile);
item->setText(0,f.fileName());
item->setText(1,f.filePath());
item->setText(2,QString::number(f.size()/1024)+" KB");
item->setIcon(0,QIcon("icons/library/track.svg"));
//Add item to list
ui->trwLibrary->addTopLevelItem(item);
}
}
I've been thinking about a small piece of code in the foreach loop, to quickly read the tags and subsequently display them in the tree widget. I know that I have to extract the last 128 bytes of the file and then parse them to extract the tags from there, but I have no clue how to do this-and the documentation wasn't helpful at all!
So, any help would be dearly appreciated.

Last but not least, I'm running on Ubuntu 9.10, with Qt 4.6, Qt Creator 1.3.0.

nix
22nd January 2010, 10:05
Hi,

You can take a look to http://developer.kde.org/~wheeler/taglib.html, it works fine for me.

Geysser
22nd January 2010, 10:46
Thanks nix! I've already seen it! But this solution is huge and complicated for me! Not to mention that I would like to do it on my own! :)