2025-11-19 20:50:15 -07:00
|
|
|
#include "playerWindow.h"
|
|
|
|
|
#include <QVBoxLayout>
|
2025-11-19 21:39:36 -07:00
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QPainterPath>
|
2025-11-19 21:20:27 -07:00
|
|
|
#include <QFileInfo>
|
2025-11-19 21:39:36 -07:00
|
|
|
#include <QCloseEvent>
|
|
|
|
|
#include "src/data/cleanerScripts.h"
|
2025-11-19 20:50:15 -07:00
|
|
|
|
|
|
|
|
PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
|
|
|
|
|
: QWidget(parent), item_(item)
|
|
|
|
|
{
|
2025-11-19 21:20:27 -07:00
|
|
|
this->setWindowTitle("Now Playing");
|
2025-11-19 21:39:36 -07:00
|
|
|
this->resize(300, 370);
|
2025-11-19 20:50:15 -07:00
|
|
|
|
2025-11-19 21:20:27 -07:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
2025-11-19 20:50:15 -07:00
|
|
|
|
2025-11-19 21:46:02 -07:00
|
|
|
// SUPER SIMPLE now:
|
|
|
|
|
spinningArt_ = new SpinningAlbumArt(item.imagePath, 250);
|
|
|
|
|
layout->addWidget(spinningArt_);
|
2025-11-19 21:39:36 -07:00
|
|
|
|
2025-11-19 21:20:27 -07:00
|
|
|
trackLabel_ = new QLabel("Track 1");
|
|
|
|
|
trackLabel_->setAlignment(Qt::AlignCenter);
|
|
|
|
|
trackLabel_->setStyleSheet("font-size: 14px; font-weight: 500;");
|
|
|
|
|
layout->addWidget(trackLabel_);
|
2025-11-19 20:50:15 -07:00
|
|
|
|
2025-11-19 21:20:27 -07:00
|
|
|
player_ = new QMediaPlayer(this);
|
2025-11-19 21:39:36 -07:00
|
|
|
audio_ = new QAudioOutput(this);
|
2025-11-19 21:20:27 -07:00
|
|
|
player_->setAudioOutput(audio_);
|
2025-11-19 20:50:15 -07:00
|
|
|
|
2025-11-19 21:39:36 -07:00
|
|
|
connect(player_, &QMediaPlayer::playbackStateChanged, this,
|
2025-11-19 21:46:02 -07:00
|
|
|
[this](QMediaPlayer::PlaybackState st){
|
2025-11-19 21:39:36 -07:00
|
|
|
if (st == QMediaPlayer::PlayingState)
|
2025-11-19 21:46:02 -07:00
|
|
|
spinningArt_->start();
|
2025-11-19 21:39:36 -07:00
|
|
|
else
|
2025-11-19 21:46:02 -07:00
|
|
|
spinningArt_->stop();
|
2025-11-19 21:39:36 -07:00
|
|
|
});
|
|
|
|
|
|
2025-11-19 21:20:27 -07:00
|
|
|
playNext();
|
2025-11-19 20:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayerWindow::playNext()
|
|
|
|
|
{
|
2025-11-19 21:20:27 -07:00
|
|
|
if (index_ >= item_.audioFiles.size()) {
|
|
|
|
|
this->close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString filePath = item_.audioFiles[index_];
|
|
|
|
|
QString fileName = QFileInfo(filePath).fileName();
|
|
|
|
|
QString title = cleanTrackTitle(fileName);
|
|
|
|
|
|
2025-11-19 21:39:36 -07:00
|
|
|
trackLabel_->setText(
|
|
|
|
|
QString("Track %1: %2").arg(index_ + 1).arg(title)
|
|
|
|
|
);
|
2025-11-19 21:20:27 -07:00
|
|
|
|
|
|
|
|
player_->setSource(QUrl::fromLocalFile(filePath));
|
|
|
|
|
player_->play();
|
|
|
|
|
|
|
|
|
|
index_++;
|
2025-11-19 20:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayerWindow::closeEvent(QCloseEvent* event)
|
|
|
|
|
{
|
|
|
|
|
if (player_) {
|
|
|
|
|
player_->stop();
|
2025-11-19 21:39:36 -07:00
|
|
|
spinTimer_->stop();
|
2025-11-19 20:50:15 -07:00
|
|
|
}
|
2025-11-19 21:39:36 -07:00
|
|
|
QWidget::closeEvent(event);
|
2025-11-19 20:50:15 -07:00
|
|
|
}
|