Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. I want to get album art image from mp3 files
QtWS25 Last Chance

I want to get album art image from mp3 files

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
15 Posts 2 Posters 1.6k Views
  • 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.
  • R Offline
    R Offline
    rhaps20
    wrote on 16 Jan 2023, 11:44 last edited by rhaps20
    #1

    os: debian11
    qt version: 6.4.2
    target : android

    I implemented like this,

    void MainWindow::metaDataChanged() {
            metaData = mediaPlayer->metaData();
            titleLabel->setText(metaData.stringValue(QMediaMetaData::Title));
            albumLabel->setText(metaData.stringValue(QMediaMetaData::AlbumTitle));
            artistLabel->setText(metaData.stringValue(QMediaMetaData::AlbumArtist));
        
        
            QVariant var = metaData.value(QMediaMetaData::CoverArtImage);
            QImage image = var.value<QImage>();
        
            albumArtLabel->setPixmap(QPixmap::fromImage(image));
        }
        
    

    This code is same with Qt Librarie's example source code[project name : Player].

    But it's not working...

    could you give me a tip?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jan 2023, 17:39 last edited by
      #2

      Hi,

      Why start a new thread when there was already that one ?

      That said, are you sure you are not doing that too early ? i.e. before the file has been loaded ?

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

      R 2 Replies Last reply 17 Jan 2023, 02:44
      0
      • S SGaist
        16 Jan 2023, 17:39

        Hi,

        Why start a new thread when there was already that one ?

        That said, are you sure you are not doing that too early ? i.e. before the file has been loaded ?

        R Offline
        R Offline
        rhaps20
        wrote on 17 Jan 2023, 02:44 last edited by rhaps20
        #3

        @SGaist said in I want to get album art image from mp3 files:

        Hi,
        Why start a new thread when there was already that one ?
        That said, are you sure you are not doing that too early ? i.e. before the file has been loaded ?

        I didn't start new thread.

        when metadata is changed, the function containing the above code is executed.

        1 Reply Last reply
        0
        • S SGaist
          16 Jan 2023, 17:39

          Hi,

          Why start a new thread when there was already that one ?

          That said, are you sure you are not doing that too early ? i.e. before the file has been loaded ?

          R Offline
          R Offline
          rhaps20
          wrote on 17 Jan 2023, 03:12 last edited by rhaps20
          #4

          @SGaist said in I want to get album art image from mp3 files:

          Hi,
          Why start a new thread when there was already that one ?
          That said, are you sure you are not doing that too early ? i.e. before the file has been loaded ?

          I succeeded the load the title, artist, album title.

          but, I can't load the album image...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 17 Jan 2023, 17:57 last edited by
            #5

            Does the documentation example show it properly ?

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

            R 1 Reply Last reply 18 Jan 2023, 07:17
            0
            • S SGaist
              17 Jan 2023, 17:57

              Does the documentation example show it properly ?

              R Offline
              R Offline
              rhaps20
              wrote on 18 Jan 2023, 07:17 last edited by
              #6

              @SGaist ```
              if (key == QMediaMetaData::CoverArtImage) {
              270 QVariant v = metaData.value(key);
              271 if (QLabel cover = qobject_cast<QLabel>(m_metaDataFields[key])) {
              272 QImage coverImage = v.value<QImage>();
              273 cover->setPixmap(QPixmap::fromImage(coverImage));
              274 }

              
              This is part of example source code...
              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 18 Jan 2023, 20:27 last edited by
                #7

                That was not my question.
                The question was whether when you run the example, it shows the image for the file you are trying to load with your own application.

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

                R 2 Replies Last reply 19 Jan 2023, 10:17
                1
                • S SGaist
                  18 Jan 2023, 20:27

                  That was not my question.
                  The question was whether when you run the example, it shows the image for the file you are trying to load with your own application.

                  R Offline
                  R Offline
                  rhaps20
                  wrote on 19 Jan 2023, 10:17 last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rhaps20
                    wrote on 19 Jan 2023, 10:40 last edited by
                    #9

                    I tried build my project to Desktop version. It also didn't show cover image.

                    1 Reply Last reply
                    0
                    • S SGaist
                      18 Jan 2023, 20:27

                      That was not my question.
                      The question was whether when you run the example, it shows the image for the file you are trying to load with your own application.

                      R Offline
                      R Offline
                      rhaps20
                      wrote on 19 Jan 2023, 11:29 last edited by
                      #10

                      @SGaist
                      Example project show image well.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 19 Jan 2023, 20:25 last edited by
                        #11

                        So compare your code with the example to find the difference that makes yours fail.

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

                        R 1 Reply Last reply 20 Jan 2023, 11:23
                        1
                        • S SGaist
                          19 Jan 2023, 20:25

                          So compare your code with the example to find the difference that makes yours fail.

                          R Offline
                          R Offline
                          rhaps20
                          wrote on 20 Jan 2023, 11:23 last edited by
                          #12

                          @SGaist
                          It seems to be a limited situation only when built with the PC version. I think its impossible on android version.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 20 Jan 2023, 22:33 last edited by
                            #13

                            I am not sure to follow you. It works on your desktop but not on Android ?

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

                            R 1 Reply Last reply 21 Jan 2023, 01:47
                            0
                            • S SGaist
                              20 Jan 2023, 22:33

                              I am not sure to follow you. It works on your desktop but not on Android ?

                              R Offline
                              R Offline
                              rhaps20
                              wrote on 21 Jan 2023, 01:47 last edited by rhaps20
                              #14

                              @SGaist said in I want to get album art image from mp3 files:

                              I am not sure to follow you. It works on your desktop but not on Android ?

                              void Player::metaDataChanged()
                              {
                                  auto metaData = m_player->metaData();
                                  setTrackInfo(QString("%1 - %2")
                                                       .arg(metaData.value(QMediaMetaData::AlbumArtist).toString())
                                                       .arg(metaData.value(QMediaMetaData::Title).toString()));
                               
                              #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
                                  for (int i = 0; i < QMediaMetaData::NumMetaData; i++) {
                                      if (QLineEdit *field = qobject_cast<QLineEdit *>(m_metaDataFields[i]))
                                          field->clear();
                                      else if (QLabel *label = qobject_cast<QLabel *>(m_metaDataFields[i]))
                                          label->clear();
                                      m_metaDataFields[i]->setDisabled(true);
                                      m_metaDataLabels[i]->setDisabled(true);
                                  }
                               
                                  for (auto &key : metaData.keys()) {
                                      int i = int(key);
                                      if (key == QMediaMetaData::CoverArtImage) {
                                          QVariant v = metaData.value(key);
                                          if (QLabel *cover = qobject_cast<QLabel *>(m_metaDataFields[key])) {
                                              QImage coverImage = v.value<QImage>();
                                              cover->setPixmap(QPixmap::fromImage(coverImage));
                                          }
                                      } else if (key == QMediaMetaData::ThumbnailImage) {
                                          QVariant v = metaData.value(key);
                                          if (QLabel *thumbnail = qobject_cast<QLabel *>(m_metaDataFields[key])) {
                                              QImage thumbnailImage = v.value<QImage>();
                                              thumbnail->setPixmap(QPixmap::fromImage(thumbnailImage));
                                          }
                                      } else if (QLineEdit *field = qobject_cast<QLineEdit *>(m_metaDataFields[key])) {
                                          QString stringValue = metaData.stringValue(key);
                                          field->setText(stringValue);
                                      }
                                      m_metaDataFields[i]->setDisabled(false);
                                      m_metaDataLabels[i]->setDisabled(false);
                                  }
                              #endif
                              }
                              

                              It's a part of example source code.

                              If you look at this source code, you will understand what I mean.

                              "#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)"

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 22 Jan 2023, 19:52 last edited by
                                #15

                                So from the looks of it, it's a metadata that cannot be retrieved on these two platforms for some reason like not provided by the platform API.

                                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

                                10/15

                                19 Jan 2023, 11:29

                                • Login

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