From 60c25e14733892b5eca61fb056655e27d06cd5a3 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 20 Apr 2020 14:23:28 +0800 Subject: [PATCH] misc: show info from audio tag if possible --- mainwindow.cpp | 25 ++++++++++++++++++++++++- mainwindow.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) 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);