Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot get metadata from audio file while loading it

Cannot get metadata from audio file while loading it

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cmoud94
    wrote on last edited by
    #1

    Hi everyone,

    I have a problem getting metadata from file while loading it from disk. I can play it etc. but can't get metadata while loading it.

    Here is my loading function:
    Btw. the "ui->playlistView" element is QTableWidget.
    @void MainWindow::on_actionOpen_triggered()
    {
    QFileDialog *fileDialog = new QFileDialog(this);
    QStringList selectedFiles;

    selectedFiles.clear();
    
    selectedFiles = fileDialog->getOpenFileNames(this, "Select songs", QDir::homePath(), "mp3 files (*.mp3)");
    if(!selectedFiles.empty()){
        playlist->clear();
        ui->playlistView->clear();
    
        ui->playlistView->setColumnCount(3);
        ui->playlistView->setHorizontalHeaderItem(0, new QTableWidgetItem("Title"));
        ui->playlistView->setHorizontalHeaderItem(1, new QTableWidgetItem("Artist"));
        ui->playlistView->setHorizontalHeaderItem(2, new QTableWidgetItem("Album"));
        ui->playlistView->setRowCount(selectedFiles.count());
    
        for(int i = 0; i < selectedFiles.count(); i++){
            playlist->addMedia(QUrl::fromLocalFile&#40;selectedFiles.at(i&#41;));
            player->setMedia(QUrl::fromLocalFile&#40;selectedFiles.at(i&#41;));
            ui->playlistView->setItem(i, 0, new QTableWidgetItem(player->metaData("").toString()));
            ui->playlistView->setItem(i, 1, new QTableWidgetItem(player->metaData("").toString()));
            ui->playlistView->setItem(i, 2, new QTableWidgetItem(player->metaData("AlbumTitle").toString()));
        }
    }
    
    player->setPlaylist(playlist);
    playlist->setCurrentIndex(0);
    

    }@

    Thanks for help. :)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should add which version of Qt you are using as well as the OS you are running on

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cmoud94
        wrote on last edited by
        #3

        Hi,

        I'm running Qt 5.2.1 (GCC 4.8.2, 64 bit) on Ubuntu 14.04. I can get the metadata for one song, but I want to list throught all loaded files and load their metadata while loading them from disk. Is there a way how to achieve it? I'm using QMediaPlayer and QMediaPlaylist for handling media and QTableWidget to display songs info in table. But I cannot get their metadata while loading them...

        Any help will be appreciated. :)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kinexd
          wrote on last edited by
          #4

          cmoud94, I am in the same predicament as you. It seems as though in Qt that it can only retrieve the metadata of a media file while it is playing. So in my code I have a play button that plays the current song in a playlist and gets the metadata as well. The first time I click the button it returns empty strings, but the second time I click the play button it gets the correct metadata. So I think I might have to use taglib for my metadata needs. @void MainWindow::playButtonclicked(){
          player->play();

          if (player->isMetaDataAvailable())
          {
            qDebug() << "there is metadata";
          }
          else
          {
            qDebug() << "No metadata.";
          }
          
          QVariant songTitle = player->metaData(QMediaMetaData::Title);
          QString songTitleString = songTitle.toString();
          ui->songLabel->setText(songTitleString);
          

          }@
          I have also found that with my if statement, the first time I click the button it will print out 'No metadata." but the second time it will print 'there is metadata'. So now I am stuck.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cmoud94
            wrote on last edited by
            #5

            Kinexd, I can get the metadata while I'm playing song or if I list through the playlist while it's loaded (with "Next Song" button). But if I try to list the playlist after it's loaded it does not work...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved