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