I want to get album art image from mp3 files
-
os: debian11
qt version: 6.4.2
target : androidI 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?
-
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 ?
@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.
-
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 ?
@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...
-
Does the documentation example show it properly ?
-
@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...
-
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. -
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. -
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. -
So compare your code with the example to find the difference that makes yours fail.
-
I am not sure to follow you. It works on your desktop but not on Android ?
-
@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)"
-
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.