Obtaining MetaData from mp3 files
-
Hello,
I have an issue with the way to get metadata from QMediaPlayer->metaData, no matter what I have tryed the metadata stays empty. Here is a working code that allow me to listening a song on my computer:
Music::Music(QObject *parent) : QObject{parent}, m_player(new QMediaPlayer), m_audioOutput(new QAudioOutput) { m_player->setAudioOutput(m_audioOutput); m_audioOutput->setVolume(50); QObject::connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &MusicModel::onMediaStatusChanged); m_player->setSource(QUrl::fromLocalFile("C:/Music/music.mp3")); m_player->play(); }
void MusicModel::onMediaStatusChanged(QMediaPlayer::MediaStatus status) { qDebug() << "onMediaStatusChanged:" << status; QMediaMetaData mmd = m_player->metaData(); qDebug() << "Title:" << mmd.value(QMediaMetaData::Title).toString(); }
Out:
onMediaStatusChanged: QMediaPlayer::LoadingMedia Title: ""
So during the entire song (+- 3 min), I only get the "LoadingMedia" once and with no MetaData inside, it appears to me that the way to get thoses informations are not like they are explain in the documentation .... I'm surely wrong but at some point I've tryed everything I could think of.
Please Help me ^^, thank's in advance.
-
Hello,
I have an issue with the way to get metadata from QMediaPlayer->metaData, no matter what I have tryed the metadata stays empty. Here is a working code that allow me to listening a song on my computer:
Music::Music(QObject *parent) : QObject{parent}, m_player(new QMediaPlayer), m_audioOutput(new QAudioOutput) { m_player->setAudioOutput(m_audioOutput); m_audioOutput->setVolume(50); QObject::connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &MusicModel::onMediaStatusChanged); m_player->setSource(QUrl::fromLocalFile("C:/Music/music.mp3")); m_player->play(); }
void MusicModel::onMediaStatusChanged(QMediaPlayer::MediaStatus status) { qDebug() << "onMediaStatusChanged:" << status; QMediaMetaData mmd = m_player->metaData(); qDebug() << "Title:" << mmd.value(QMediaMetaData::Title).toString(); }
Out:
onMediaStatusChanged: QMediaPlayer::LoadingMedia Title: ""
So during the entire song (+- 3 min), I only get the "LoadingMedia" once and with no MetaData inside, it appears to me that the way to get thoses informations are not like they are explain in the documentation .... I'm surely wrong but at some point I've tryed everything I could think of.
Please Help me ^^, thank's in advance.
@Darta
Per https://stackoverflow.com/a/64037175/489865 I believe your code is correct (though see later on). From code there what does your// Get the list of keys there is metadata available for QStringList metadatalist = player->availableMetaData();
return? And have you tried some other
.mp3
file just in case?You may be supposed to wait for
QMediaPlayer::LoadedMedia
status? But you are saying you get onlyQMediaPlayer::LoadingMedia
? For the sake of checking, if you instead set a timer for few seconds or whatever, on timeout what do you get for media status and metadata?Check posts
https://stackoverflow.com/questions/45696232/qmediaplayer-not-loading-media-and-not-emitting-mediastatuschanged-signals
https://stackoverflow.com/questions/77186011/qmediaplayer-fails-to-play-mp3-file-and-does-not-signals-mediastatuschangedqmed
Are these relevant to your case?I take it you mean the mp3 does actually play? It may be relevant to state your platform and exact Qt version. For example one post claimed that it did not work under Qt 6.5.1 but did work under 6.5.3.
-
Yes thank you for your answer,
apparently my version of Qt is a bit outdate, I was under Qt 6.4.2 .... So I made an update to 6.9.1, and now keeping the same code I just lost the music, here is my new output :qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later onMediaStatusChanged: QMediaPlayer::LoadingMedia Title: ""
And when I close the application a red message appears right befor closing itself, like a bad joke it gives me that:
[mp3 @ 0000019990a05240] Skipping 626 bytes of junk at 35482. [mp3 @ 0000019990a05240] Estimating duration from bitrate, this may be inaccurate Input #0, mp3, from 'D:/Music/AC_DC/Back In Black/06 Back In Black.mp3': Metadata: album : Back In Black artist : AC/DC genre : Rock track : 6/10 title : Back In Black date : 1980 Duration: 00:04:16.03, start: 0.000000, bitrate: 193 kb/s Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 192 kb/s Stream #0:1: Video: png, rgb24(pc, gbr/unknown/unknown), 649x649 [SAR 2834:2834 DAR 1:1], 90k tbr, 90k tbn (attached pic) Metadata: comment : Other 20:34:40: La commande « D:\Projets\Developpement\C++\QT\MusicMaker\build\Debug\MusicMaker.exe » s’est terminée avec succès.
so I've used the links that you gave me and tested a solution given to replace the connect and it gives that :
QObject::connect(m_player, &QMediaPlayer::mediaStatusChanged, m_player, [this](QMediaPlayer::MediaStatus status) { qDebug() << "onMediaStatusChanged:" << status; if (status == QMediaPlayer::LoadedMedia) { qDebug() << "test1"; if (m_player) qDebug() << m_player->duration(); qDebug() << "test2"; } });
And there I have a segfault every times I use m_player and here is the output:
Ok My bad I just replaced the second "m_player" by "this" and the segfault is no longerqt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later onMediaStatusChanged: QMediaPlayer::LoadingMedia onMediaStatusChanged: QMediaPlayer::LoadedMedia test1 21:24:46: La commande « D:\Projets\Developpement\C++\QT\MusicMaker\build\Debug\MusicMaker.exe » s’est terminée de manière anormale.
And for the final test if I remove the call of m_player inside the connect here is the output:
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later onMediaStatusChanged: QMediaPlayer::LoadingMedia onMediaStatusChanged: QMediaPlayer::LoadedMedia test1 test2 onMediaStatusChanged: QMediaPlayer::BufferingMedia QAudioSink::start: QAudioFormat not supported by QAudioDevice onMediaStatusChanged: QMediaPlayer::BufferedMedia
with time a new message is added:
onMediaStatusChanged: QMediaPlayer::EndOfMedia
and I keep the red message with metaData when I close the application.
So I guess that I started with something bugged that would have never work because of Qt, to end up with a dual issue that I'm not sure how to solve. I guess it's an improvement lol
now I just have to understand why the QAudioFormat not supported for a simple mp3 file -
Yes thank you for your answer,
apparently my version of Qt is a bit outdate, I was under Qt 6.4.2 .... So I made an update to 6.9.1, and now keeping the same code I just lost the music, here is my new output :qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later onMediaStatusChanged: QMediaPlayer::LoadingMedia Title: ""
And when I close the application a red message appears right befor closing itself, like a bad joke it gives me that:
[mp3 @ 0000019990a05240] Skipping 626 bytes of junk at 35482. [mp3 @ 0000019990a05240] Estimating duration from bitrate, this may be inaccurate Input #0, mp3, from 'D:/Music/AC_DC/Back In Black/06 Back In Black.mp3': Metadata: album : Back In Black artist : AC/DC genre : Rock track : 6/10 title : Back In Black date : 1980 Duration: 00:04:16.03, start: 0.000000, bitrate: 193 kb/s Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 192 kb/s Stream #0:1: Video: png, rgb24(pc, gbr/unknown/unknown), 649x649 [SAR 2834:2834 DAR 1:1], 90k tbr, 90k tbn (attached pic) Metadata: comment : Other 20:34:40: La commande « D:\Projets\Developpement\C++\QT\MusicMaker\build\Debug\MusicMaker.exe » s’est terminée avec succès.
so I've used the links that you gave me and tested a solution given to replace the connect and it gives that :
QObject::connect(m_player, &QMediaPlayer::mediaStatusChanged, m_player, [this](QMediaPlayer::MediaStatus status) { qDebug() << "onMediaStatusChanged:" << status; if (status == QMediaPlayer::LoadedMedia) { qDebug() << "test1"; if (m_player) qDebug() << m_player->duration(); qDebug() << "test2"; } });
And there I have a segfault every times I use m_player and here is the output:
Ok My bad I just replaced the second "m_player" by "this" and the segfault is no longerqt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later onMediaStatusChanged: QMediaPlayer::LoadingMedia onMediaStatusChanged: QMediaPlayer::LoadedMedia test1 21:24:46: La commande « D:\Projets\Developpement\C++\QT\MusicMaker\build\Debug\MusicMaker.exe » s’est terminée de manière anormale.
And for the final test if I remove the call of m_player inside the connect here is the output:
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later onMediaStatusChanged: QMediaPlayer::LoadingMedia onMediaStatusChanged: QMediaPlayer::LoadedMedia test1 test2 onMediaStatusChanged: QMediaPlayer::BufferingMedia QAudioSink::start: QAudioFormat not supported by QAudioDevice onMediaStatusChanged: QMediaPlayer::BufferedMedia
with time a new message is added:
onMediaStatusChanged: QMediaPlayer::EndOfMedia
and I keep the red message with metaData when I close the application.
So I guess that I started with something bugged that would have never work because of Qt, to end up with a dual issue that I'm not sure how to solve. I guess it's an improvement lol
now I just have to understand why the QAudioFormat not supported for a simple mp3 file -
So after all thoses update I felt like I should restart a small project so there it is:
-
Qt Creator 17
-
Qt 6.9.1 with MSVC 20022, x86_64
-
Windows 11 pro
MusicM.cpp
MusicM::MusicM(QObject *parent) : QObject{parent}, m_player(new QMediaPlayer(this)), m_output(new QAudioOutput(m_player)) { m_player->setAudioOutput(m_output); m_player->setSource(QUrl::fromLocalFile("D:/Music/AC_DC/Back In Black/06 Back In Black.mp3")); m_output->setVolume(50); } void MusicM::lect() { qDebug() << "Playing:" << m_player->source(); m_player->play(); }
main.cpp
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); MusicM mm; mm.lect(); return a.exec(); }
Output
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later Playing: QUrl("file:///D:/Music/AC_DC/Back In Black/06 Back In Black.mp3") qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: "Immediate exit requested"
So windows or any mediaPlayer can read thoses mp3 files and get MetaData from theme, apparently only Qt faile to success at it no matter the version or what so ever .... and just following the poor documentation about it doesn't work either...
If anyone could help me shed some light on this subject it would be much appreciated. thank's in advance !
-
-
So after all thoses update I felt like I should restart a small project so there it is:
-
Qt Creator 17
-
Qt 6.9.1 with MSVC 20022, x86_64
-
Windows 11 pro
MusicM.cpp
MusicM::MusicM(QObject *parent) : QObject{parent}, m_player(new QMediaPlayer(this)), m_output(new QAudioOutput(m_player)) { m_player->setAudioOutput(m_output); m_player->setSource(QUrl::fromLocalFile("D:/Music/AC_DC/Back In Black/06 Back In Black.mp3")); m_output->setVolume(50); } void MusicM::lect() { qDebug() << "Playing:" << m_player->source(); m_player->play(); }
main.cpp
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); MusicM mm; mm.lect(); return a.exec(); }
Output
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later Playing: QUrl("file:///D:/Music/AC_DC/Back In Black/06 Back In Black.mp3") qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: "Immediate exit requested"
So windows or any mediaPlayer can read thoses mp3 files and get MetaData from theme, apparently only Qt faile to success at it no matter the version or what so ever .... and just following the poor documentation about it doesn't work either...
If anyone could help me shed some light on this subject it would be much appreciated. thank's in advance !
-
-
Yes I've seen that, so I've been looking into it and what I figured out is that Qt change the way of playing songs by using external FFmpeg librairies to deal with the multimedia, now I'm not sur if it is FFmpeg last version who is bugged or if it is Qt who is poorly using thoses libraries but I took the Media Player example made by Qt with Qt, and I have the exact same issue, I've been looking and I found ppl with the same issue, so in fact there is nothing I can do to make it work, it's just bugged, Thank's Qt !!!!
I remember 10 years ago it took me 10 minutes to play a song with a Qt app and now it's just not possible lol !!!
So What I'm telling myself is, the best way to make a Media Player with Qt is to take a very very very old version -
Yes I've seen that, so I've been looking into it and what I figured out is that Qt change the way of playing songs by using external FFmpeg librairies to deal with the multimedia, now I'm not sur if it is FFmpeg last version who is bugged or if it is Qt who is poorly using thoses libraries but I took the Media Player example made by Qt with Qt, and I have the exact same issue, I've been looking and I found ppl with the same issue, so in fact there is nothing I can do to make it work, it's just bugged, Thank's Qt !!!!
I remember 10 years ago it took me 10 minutes to play a song with a Qt app and now it's just not possible lol !!!
So What I'm telling myself is, the best way to make a Media Player with Qt is to take a very very very old version@Darta said in Obtaining MetaData from mp3 files:
now I'm not sur if it is FFmpeg last version who is bugged or if it is Qt who is poorly using thoses libraries
So, did you try what @JonB suggested?
-
Yes I tried and it works fine so it's more Qt who don't know how to use ffmpeg,
So the issue is that MediaPlayer isn't working for most version of Qt ...
I just installed Qt 6.5.3 and the code works perfectly now, or at least the minial version of playing a song works I still have to try to get MetaData correctly now haha .... -
Sooooo,
QMediaMetaData tmp = m_mp->metaData(); m_singers = tmp.value(QMediaMetaData::ContributingArtist).toString(); m_title = tmp.value(QMediaMetaData::Title).toString(); m_album = tmp.value(QMediaMetaData::AlbumTitle).toString(); m_duration = tmp.value(QMediaMetaData::Duration).toULongLong(); qDebug() << "Path:" << m_path; qDebug() << "Singers:" << m_singers; qDebug() << "Title:" << m_title; qDebug() << "Album:" << m_album;
Works Fine !
-