QMediaPlayer MetaData Unavailable?



  • 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



  • 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...


  • Qt Champions 2018



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

    Thanks for the reply,
    Alex



  • @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"));



  • @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


 

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