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. QMediaPlayer MetaData Unavailable?
QtWS25 Last Chance

QMediaPlayer MetaData Unavailable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
audioqmediaplayer
7 Posts 3 Posters 2.0k 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.
  • W Offline
    W Offline
    wumpus7
    wrote on 10 Sept 2019, 23:56 last edited by
    #1

    Howdy,

    I'm using a QMediaPlayer to play back .wav files. Playback is working, but I don't seem to be able to get any meta data about the file. In particular, I need the channel count.

    I've tried embedding this:

            QStringList metaDataList = player->availableMetaData();
            qDebug("Available metadata keys:  %d",metaDataList.length());
    

    into the QMediaPlayer::LoadedMedia case of my mediaStatusChanged handler. It prints out '0' available keys for each track I select and load.

    I've also tried a variety of other callback handlers:

    • metaDataChanged()
    • metaDataChanged(const QString &key, const QVariant &value)
    • metaDataAvailableChanged(bool available)

    None of them is ever hit, even after playing the file.

    I've also looked at this example: https://doc.qt.io/qt-5.10/qtmultimedia-multimediawidgets-player-player-cpp.html

    I think I'm doing everything required there, but I still never hit the metaDataChanged() callback.

    Do I need to use a QMediaPlaylist to get that functionality? Everything I've read says that since QMediaPlayer inherits from QMediaObject, I should be able to get metadata directly from it.

    Thanks,
    Alex

    W A 2 Replies Last reply 11 Sept 2019, 00:08
    0
    • W wumpus7
      10 Sept 2019, 23:56

      Howdy,

      I'm using a QMediaPlayer to play back .wav files. Playback is working, but I don't seem to be able to get any meta data about the file. In particular, I need the channel count.

      I've tried embedding this:

              QStringList metaDataList = player->availableMetaData();
              qDebug("Available metadata keys:  %d",metaDataList.length());
      

      into the QMediaPlayer::LoadedMedia case of my mediaStatusChanged handler. It prints out '0' available keys for each track I select and load.

      I've also tried a variety of other callback handlers:

      • metaDataChanged()
      • metaDataChanged(const QString &key, const QVariant &value)
      • metaDataAvailableChanged(bool available)

      None of them is ever hit, even after playing the file.

      I've also looked at this example: https://doc.qt.io/qt-5.10/qtmultimedia-multimediawidgets-player-player-cpp.html

      I think I'm doing everything required there, but I still never hit the metaDataChanged() callback.

      Do I need to use a QMediaPlaylist to get that functionality? Everything I've read says that since QMediaPlayer inherits from QMediaObject, I should be able to get metadata directly from it.

      Thanks,
      Alex

      W Offline
      W Offline
      wumpus7
      wrote on 11 Sept 2019, 00:08 last edited by
      #2

      I found this ancient post in this forum that seems relevant: Can't get MetaData of URL using QMediaPlayer. I am using setMedia(URL).

      No real response or fix in five years...

      J 1 Reply Last reply 11 Sept 2019, 04:46
      0
      • W wumpus7
        11 Sept 2019, 00:08

        I found this ancient post in this forum that seems relevant: Can't get MetaData of URL using QMediaPlayer. I am using setMedia(URL).

        No real response or fix in five years...

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 11 Sept 2019, 04:46 last edited by
        #3

        @wumpus7 Try https://doc.qt.io/qt-5/qmediaplaylist.html#mediaObject and then https://doc.qt.io/qt-5/qmediaobject.html#availableMetaData

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        W 1 Reply Last reply 11 Sept 2019, 19:27
        1
        • J jsulm
          11 Sept 2019, 04:46

          @wumpus7 Try https://doc.qt.io/qt-5/qmediaplaylist.html#mediaObject and then https://doc.qt.io/qt-5/qmediaobject.html#availableMetaData

          W Offline
          W Offline
          wumpus7
          wrote on 11 Sept 2019, 19:27 last edited by
          #4

          @jsulm - I'm not using a playlist, so I can't use QMediaPlaylist::mediaObject().

          Thanks for the reply,
          Alex

          1 Reply Last reply
          0
          • W wumpus7
            10 Sept 2019, 23:56

            Howdy,

            I'm using a QMediaPlayer to play back .wav files. Playback is working, but I don't seem to be able to get any meta data about the file. In particular, I need the channel count.

            I've tried embedding this:

                    QStringList metaDataList = player->availableMetaData();
                    qDebug("Available metadata keys:  %d",metaDataList.length());
            

            into the QMediaPlayer::LoadedMedia case of my mediaStatusChanged handler. It prints out '0' available keys for each track I select and load.

            I've also tried a variety of other callback handlers:

            • metaDataChanged()
            • metaDataChanged(const QString &key, const QVariant &value)
            • metaDataAvailableChanged(bool available)

            None of them is ever hit, even after playing the file.

            I've also looked at this example: https://doc.qt.io/qt-5.10/qtmultimedia-multimediawidgets-player-player-cpp.html

            I think I'm doing everything required there, but I still never hit the metaDataChanged() callback.

            Do I need to use a QMediaPlaylist to get that functionality? Everything I've read says that since QMediaPlayer inherits from QMediaObject, I should be able to get metadata directly from it.

            Thanks,
            Alex

            A Offline
            A Offline
            anil_arise
            wrote on 13 Sept 2019, 06:00 last edited by anil_arise
            #5

            @wumpus7 To get availableMetaData of QMediaplayer should be in loaded media status or Playing State or Pause State.
            to add media file to QMediaplayer setMedia(QUrl::fromLocalFile("path to media file"));

            W 1 Reply Last reply 13 Sept 2019, 20:15
            0
            • A anil_arise
              13 Sept 2019, 06:00

              @wumpus7 To get availableMetaData of QMediaplayer should be in loaded media status or Playing State or Pause State.
              to add media file to QMediaplayer setMedia(QUrl::fromLocalFile("path to media file"));

              W Offline
              W Offline
              wumpus7
              wrote on 13 Sept 2019, 20:15 last edited by
              #6

              @anil_arise - here's what I'm doing:

              void LocalDiskAudioInterface::mediaStatusChanged(QMediaPlayer::MediaStatus status)
              {
              switch (status)
              {
              case QMediaPlayer::EndOfMedia:
              if (!playOne)
              next();
              break;
              case QMediaPlayer::LoadedMedia:
              {
              qDebug("Validating track: %d",currentTrackIndex);

                      QVariantMap song = songs.at(currentTrackIndex).toMap();
                      qDebug("name:  %s",qPrintable(song["name"].toString()));
              
                      QString duration = LoudUtils::timeAsString(player->duration() / 1000);
                      qDebug("time:  %s",qPrintable(duration));
                      song.insert("duration", duration);
              
                      song.insert("invalid", false);
              
                      QMediaContent audioFile = player->currentMedia();
                      qDebug("Media Content %s available!",audioFile.isNull()? "is NOT" : "is");
              
                      bool metaDataAvailable = player->isMetaDataAvailable();
                      qDebug("Metadata %s available!",metaDataAvailable? "is" : "is NOT");
              
                      QStringList metaDataList = player->availableMetaData();
                      qDebug("Available metadata keys:  %d",metaDataList.length());
              
                      songs[currentTrackIndex] = song;
              
                      emit songsChanged();
                      emit trackChanged();
                      break;
                  }
                  case QMediaPlayer::InvalidMedia:
                  {
                      qDebug("Invalidating track:  %d",currentTrackIndex);
              
                      QVariantMap song = songs.at(currentTrackIndex).toMap();
                      qDebug("name:  %s",qPrintable(song["name"].toString()));
              
                      song.insert("invalid", true);   // media player refused to load song...
              
                      songs[currentTrackIndex] = song;
              
                      emit songsChanged();
                      emit trackChanged();
                      break;
                  }
                  default:
                      break;
              }
              

              }

              Also:

              void LocalDiskAudioInterface::metaDataAvailableChanged(bool available)
              {
              if (available)
              {
              ...
              }
              }

              for good measure. The former hits at LoadedMedia and logs that the currentMedia is non-NULL, but there is no metadata available, and thus there are no keys. (The duration value is obtained from the player, and is accurate.) The latter (metaDataAvailableChanged) is never hit.

              Are there other people who have actually obtained metadata from QMediaPlayer? I've found lots of posts from people who are or were having trouble with this.

              Thanks,
              Alex

              W 1 Reply Last reply 1 Oct 2019, 00:52
              0
              • W wumpus7
                13 Sept 2019, 20:15

                @anil_arise - here's what I'm doing:

                void LocalDiskAudioInterface::mediaStatusChanged(QMediaPlayer::MediaStatus status)
                {
                switch (status)
                {
                case QMediaPlayer::EndOfMedia:
                if (!playOne)
                next();
                break;
                case QMediaPlayer::LoadedMedia:
                {
                qDebug("Validating track: %d",currentTrackIndex);

                        QVariantMap song = songs.at(currentTrackIndex).toMap();
                        qDebug("name:  %s",qPrintable(song["name"].toString()));
                
                        QString duration = LoudUtils::timeAsString(player->duration() / 1000);
                        qDebug("time:  %s",qPrintable(duration));
                        song.insert("duration", duration);
                
                        song.insert("invalid", false);
                
                        QMediaContent audioFile = player->currentMedia();
                        qDebug("Media Content %s available!",audioFile.isNull()? "is NOT" : "is");
                
                        bool metaDataAvailable = player->isMetaDataAvailable();
                        qDebug("Metadata %s available!",metaDataAvailable? "is" : "is NOT");
                
                        QStringList metaDataList = player->availableMetaData();
                        qDebug("Available metadata keys:  %d",metaDataList.length());
                
                        songs[currentTrackIndex] = song;
                
                        emit songsChanged();
                        emit trackChanged();
                        break;
                    }
                    case QMediaPlayer::InvalidMedia:
                    {
                        qDebug("Invalidating track:  %d",currentTrackIndex);
                
                        QVariantMap song = songs.at(currentTrackIndex).toMap();
                        qDebug("name:  %s",qPrintable(song["name"].toString()));
                
                        song.insert("invalid", true);   // media player refused to load song...
                
                        songs[currentTrackIndex] = song;
                
                        emit songsChanged();
                        emit trackChanged();
                        break;
                    }
                    default:
                        break;
                }
                

                }

                Also:

                void LocalDiskAudioInterface::metaDataAvailableChanged(bool available)
                {
                if (available)
                {
                ...
                }
                }

                for good measure. The former hits at LoadedMedia and logs that the currentMedia is non-NULL, but there is no metadata available, and thus there are no keys. (The duration value is obtained from the player, and is accurate.) The latter (metaDataAvailableChanged) is never hit.

                Are there other people who have actually obtained metadata from QMediaPlayer? I've found lots of posts from people who are or were having trouble with this.

                Thanks,
                Alex

                W Offline
                W Offline
                wumpus7
                wrote on 1 Oct 2019, 00:52 last edited by
                #7

                It seems remarkable to me that the QMediaPlayer can know whether I'm playing back audio with 1, 2, or more channels, but I cannot get that information from it, but I guess that's just the way it is? It seems like some people can get this to work, and others can't, so I wonder if this is another issue of platform differences? (For reference, this is playback either via a wired connection to an MFi device, or directly on an iPad/iPhone, so iOS under the hood.)

                Anyway, I've given up on displaying mono/stereo channel information in our implementation. (The player will fail to play back audio with three or more channels, so I can at least flag that. It'd be nice to label, but it's not required.) I'll report a bug if I get the time at some point.

                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