[Solved] reading ID3 tags from MP3 files



  • Hello everyone!

    I'm trying to do a mp3 files organizer, (My collection is all messed up), but I'm having problems to read the ID3 tags from the mp3 files.

    I'm using the code below to read the tags and move the files to the correct directories, but the methods always returns empty strings!

    While studing the API documentation, i found that I needed to wait the state changes to StoppedState, but it never changes. As you can see, i commented the line tthat waits until its changed because it locks the code at that point and never gets out.

    I've searched for some time, and find no solution. Can anyone help me?

    Thanks in Advance!

    @
    void Organizer::tratarMp3(Phonon::MediaObject *arquivo, QString dirRaiz, QString filePath){
    QMultiMap<QString, QString> tags;
    QDir dir(dirRaiz);

     //  while(temp.state()!=Phonon::StoppedState);
    
    tags = arquivo->metaData();
    
    if(tags.value("ARTIST").isEmpty()){
        dirRaiz.append("Outras/");
    }
    
    else{
        dirRaiz.append(tags.value("ARTIST"));
        dirRaiz.append("/");
    }
    
    if(!tags.value("ALBUM").isEmpty()){
        dirRaiz.append(tags.value("ALBUM"));
        dirRaiz.append("/");
    }
    
    else{
        dirRaiz.append("Outras/");
    }
    
    dir.setPath(dirRaiz);
    
    if(!dir.exists())
        dir.mkpath(dir.path());
    
    dirRaiz.append(arquivo->currentSource().fileName());
    
    QFile::copy(filePath,dirRaiz);
    
    //QFile::remove(arquivo.filePath());
    

    }
    @



  • That busy loop locks the thread, and prevents any QEvents from being handled by the event loop.

    You should signals and slots to detect changes in Phonon's state.

    Create a slot and connect it to "MediaObject::stateChanged":http://doc.qt.nokia.com/latest/phonon-mediaobject.html#stateChanged, then inside that slot determine whether you can call tratarMp3().



  • Sorry for taking so long to post a reply! It worked, but i ended up using the Taglib libraries to support more formats. Thanks for the Help!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.