diff --git a/mainwindow.cpp b/mainwindow.cpp index 6aeffc6..cfdd16a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -121,6 +121,21 @@ void MainWindow::setAudioPropertyInfoForDisplay(int sampleRate, int bitrate, int ui->propLabel->setToolTip(tooltipStrs.join('\n')); } +void MainWindow::setAudioMetadataForDisplay(QString title, QString artist, QString album) +{ + Q_UNUSED(album); + + if (!title.isEmpty()) { + 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)); + } else { + ui->titleLabel->setText(QString("%1").arg(artist)); + } + } +} + void MainWindow::localSocketPlayAudioFiles(QVariant audioFilesVariant) { QStringList urlStrList = audioFilesVariant.toStringList(); @@ -417,11 +432,19 @@ void MainWindow::initConnections() suffix = suffix.toUpper(); TagLib::FileRef fileRef(filePath.toLocal8Bit().data()); - if(!fileRef.isNull() && fileRef.audioProperties()) { + + if (!fileRef.isNull() && fileRef.audioProperties()) { TagLib::AudioProperties *prop = fileRef.audioProperties(); setAudioPropertyInfoForDisplay(prop->sampleRate(), prop->bitrate(), prop->channels(), suffix); } + if (!fileRef.isNull() && fileRef.tag()) { + TagLib::Tag * tag = fileRef.tag(); + setAudioMetadataForDisplay(QString::fromStdString(tag->title().to8Bit(true)), + QString::fromStdString(tag->artist().to8Bit(true)), + QString::fromStdString(tag->album().to8Bit(true))); + } + using namespace spID3; using namespace spFLAC; diff --git a/mainwindow.h b/mainwindow.h index 07dee36..c48ba71 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -24,6 +24,7 @@ public: void commandlinePlayAudioFiles(QStringList audioFiles); void loadPlaylistBySingleLocalFile(const QString &path); void setAudioPropertyInfoForDisplay(int sampleRate, int bitrate, int channelCount, QString audioExt); + void setAudioMetadataForDisplay(QString title, QString artist, QString album); public slots: void localSocketPlayAudioFiles(QVariant audioFilesVariant);