From ae2fb13345aedbcac4b1a389a7ece9ede0f61656 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 20 Apr 2020 14:39:45 +0800 Subject: [PATCH] fix: display default album cover and other fix --- mainwindow.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index cfdd16a..b96ac62 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -129,9 +129,9 @@ void MainWindow::setAudioMetadataForDisplay(QString title, QString artist, QStri if (!artist.isEmpty()) { ui->titleLabel->setText(QString("%1 - %2").arg(artist, title)); } else if (!album.isEmpty()) { - ui->titleLabel->setText(QString("%1 - %2").arg(artist, album)); + ui->titleLabel->setText(QString("%1 - %2").arg(album, title)); } else { - ui->titleLabel->setText(QString("%1").arg(artist)); + ui->titleLabel->setText(QString("%1").arg(title)); } } } @@ -448,19 +448,27 @@ void MainWindow::initConnections() using namespace spID3; using namespace spFLAC; + bool coverLoaded = false; + if (suffix == "MP3") { if (spID3::loadPictureData(filePath.toLocal8Bit().data())) { + coverLoaded = true; QByteArray picData((const char*)spID3::getPictureDataPtr(), spID3::getPictureLength()); ui->coverLabel->setPixmap(QPixmap::fromImage(QImage::fromData(picData))); spID3::freePictureData(); } } else if (suffix == "FLAC") { if (spFLAC::loadPictureData(filePath.toLocal8Bit().data())) { + coverLoaded = true; QByteArray picData((const char*)spFLAC::getPictureDataPtr(), spFLAC::getPictureLength()); ui->coverLabel->setPixmap(QPixmap::fromImage(QImage::fromData(picData))); spFLAC::freePictureData(); } } + + if (!coverLoaded) { + ui->coverLabel->setPixmap(QPixmap(":/icons/icons/media-album-cover.svg")); + } } });