Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

not getting proper metadata from a media file .



  • i made a function to get the metadata .
    but i am not getting all the metadata .example like duration.

            QStringList infos;
            QStringList metadatalist = m_player->availableMetaData();
            int list_size = metadatalist.size();
            QString metadata_key;
            QVariant var_data;
    
            for (int indx = 0; indx < list_size; indx++)
            {
                metadata_key  = metadatalist.at(indx);
                var_data      = m_player->metaData(metadata_key);
    
                infos << QString(metadata_key + QString(" : %1").arg(var_data.toString()));
            }
    

    i am not getting duration for example.

    but i am getting duration by this code

    float pi = m_player->duration()/60001;
    

    what is wrong?


  • Lifetime Qt Champion

    @saber
    Hi
    Maybe duration is not included in the meta data.
    m_player->duration() not from meta data as far as i know.



  • @mrjj
    ok got that.
    another issue .

    float pi = m_player->duration()/60001;
    

    dose giving me a round number(5,9,8) instead of float number (3.5,2.5).


  • Lifetime Qt Champion

    @saber
    Hi
    Try
    float pi = m_player->duration()/60001.0; // note the extra .0

    if m_player->duration() returns INT
    float pi = (float)m_player->duration()/60001.0;

    or the very c++ way
    float pi = static_cast<float>(m_player->duration())/60001;



  • here is the final function

    //in constractor
    
    m_player = new QMediaPlayer(this);
            m_player->setMedia(QUrl::fromLocalFile(pathName));
            connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
                    this, SLOT(detailmedia(QMediaPlayer::MediaStatus)));
    
    void propertiesw::detailmedia(QMediaPlayer::MediaStatus status)
    {
        if (status == QMediaPlayer::LoadedMedia){
    
             QStringList infos;
            QStringList metadatalist = m_player->availableMetaData();
            int list_size = metadatalist.size();
            QString metadata_key;
            QVariant var_data;
    
            for (int indx = 0; indx < list_size; indx++)
            {
                metadata_key  = metadatalist.at(indx);
                var_data      = m_player->metaData(metadata_key);
    
                infos << QString(metadata_key + QString(" : %1").arg(var_data.toString()));
            }
    
            float pi = m_player->duration()/60000.0;
    
            infos << QString("Duration"+ QString(" : %1").arg(QString::number(pi)));
        }
    }
    

  • Lifetime Qt Champion

    ok :)
    so .0 was enough ?



  • @mrjj

    yes.
    as simple as can be.


Log in to reply