Add song title to current playing screen

This commit is contained in:
2025-11-19 21:20:27 -07:00
parent 1934dbe83a
commit ec11876c2e
27 changed files with 103 additions and 32 deletions

View File

@@ -2,46 +2,66 @@
#include <QVBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QFileInfo>
PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
: QWidget(parent), item_(item)
{
this->setWindowTitle("Now Playing");
this->resize(300, 300);
this->setWindowTitle("Now Playing");
this->resize(300, 350);
QVBoxLayout* layout = new QVBoxLayout(this);
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* art = new QLabel;
QPixmap pix(item.imagePath);
art->setPixmap(pix.scaled(250, 250, Qt::KeepAspectRatio, Qt::SmoothTransformation));
art->setAlignment(Qt::AlignCenter);
// Album Art
QLabel* art = new QLabel;
QPixmap pix(item.imagePath);
art->setPixmap(pix.scaled(250, 250, Qt::KeepAspectRatio, Qt::SmoothTransformation));
art->setAlignment(Qt::AlignCenter);
layout->addWidget(art);
layout->addWidget(art);
// Track Label (new)
trackLabel_ = new QLabel("Track 1");
trackLabel_->setAlignment(Qt::AlignCenter);
trackLabel_->setStyleSheet("font-size: 14px; font-weight: 500;");
layout->addWidget(trackLabel_);
player_ = new QMediaPlayer(this);
audio_ = new QAudioOutput(this);
// Player setup
player_ = new QMediaPlayer(this);
audio_ = new QAudioOutput(this);
player_->setAudioOutput(audio_);
player_->setAudioOutput(audio_);
connect(player_, &QMediaPlayer::mediaStatusChanged, this,
[this](QMediaPlayer::MediaStatus s){
if (s == QMediaPlayer::EndOfMedia) {
playNext();
}
});
connect(player_, &QMediaPlayer::mediaStatusChanged, this, [this](QMediaPlayer::MediaStatus s){
if (s == QMediaPlayer::EndOfMedia) {
playNext();
}
});
playNext();
playNext();
}
void PlayerWindow::playNext()
{
if (index_ >= item_.audioFiles.size()) {
this->close();
return;
}
if (index_ >= item_.audioFiles.size()) {
this->close();
return;
}
player_->setSource(QUrl::fromLocalFile(item_.audioFiles[index_]));
player_->play();
index_++;
QString filePath = item_.audioFiles[index_];
QString fileName = QFileInfo(filePath).fileName();
// Remove extension for cleaner title
QString title = cleanTrackTitle(fileName);
// Track number is index + 1
int trackNumber = index_ + 1;
trackLabel_->setText(QString("Track %1: %2").arg(trackNumber).arg(title));
player_->setSource(QUrl::fromLocalFile(filePath));
player_->play();
index_++;
}
// Stop the music when the window is closed