Files
Qt-Music-Player/src/windows/playerWindow/playerWindow.cpp

70 lines
1.7 KiB
C++
Raw Normal View History

#include "playerWindow.h"
#include <QVBoxLayout>
#include <QPainter>
#include <QPainterPath>
#include <QFileInfo>
#include <QCloseEvent>
#include "src/data/cleanerScripts.h"
PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
: QWidget(parent), item_(item)
{
this->setWindowTitle("Now Playing");
this->resize(300, 370);
QVBoxLayout* layout = new QVBoxLayout(this);
// SUPER SIMPLE now:
spinningArt_ = new SpinningAlbumArt(item.imagePath, 250);
layout->addWidget(spinningArt_);
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_->setAudioOutput(audio_);
connect(player_, &QMediaPlayer::playbackStateChanged, this,
[this](QMediaPlayer::PlaybackState st){
if (st == QMediaPlayer::PlayingState)
spinningArt_->start();
else
spinningArt_->stop();
});
playNext();
}
void PlayerWindow::playNext()
{
if (index_ >= item_.audioFiles.size()) {
this->close();
return;
}
QString filePath = item_.audioFiles[index_];
QString fileName = QFileInfo(filePath).fileName();
QString title = cleanTrackTitle(fileName);
trackLabel_->setText(
QString("Track %1: %2").arg(index_ + 1).arg(title)
);
player_->setSource(QUrl::fromLocalFile(filePath));
player_->play();
index_++;
}
void PlayerWindow::closeEvent(QCloseEvent* event)
{
if (player_) {
player_->stop();
spinTimer_->stop();
}
QWidget::closeEvent(event);
}