Update current music player to have round spinning album art
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1360,16 +1360,13 @@ moc_playerWindow.cpp: ../../src/windows/playerWindow/playerWindow.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qmediaplayer.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QAudioOutput \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qaudiooutput.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QTimer \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qtimer.h \
|
||||
../../src/data/albumInformation.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QString \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qstring.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QStringList \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qstringlist.h \
|
||||
../../src/data/cleanerScripts.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QRegularExpression \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qregularexpression.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QFileInfo \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qfileinfo.h \
|
||||
moc_predefs.h \
|
||||
/opt/homebrew/share/qt/libexec/moc
|
||||
/opt/homebrew/share/qt/libexec/moc $(DEFINES) --include /Users/lucas/Developer/Qt-Music-Player/build/Desktop-Debug/moc_predefs.h -I/opt/homebrew/share/qt/mkspecs/macx-clang -I/Users/lucas/Developer/Qt-Music-Player -I/opt/homebrew/lib/QtWidgets.framework/Headers -I/opt/homebrew/lib/QtMultimedia.framework/Headers -I/opt/homebrew/lib/QtGui.framework/Headers -I/opt/homebrew/lib/QtNetwork.framework/Headers -I/opt/homebrew/lib/QtCore.framework/Headers -I. -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -I/Library/Developer/CommandLineTools/usr/lib/clang/17/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include -F/opt/homebrew/lib ../../src/windows/playerWindow/playerWindow.h -o moc_playerWindow.cpp
|
||||
@@ -1479,11 +1476,8 @@ musicSelector.o: ../../src/windows/musicSelector/musicSelector.cpp ../../src/win
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qmediaplayer.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QAudioOutput \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qaudiooutput.h \
|
||||
../../src/data/cleanerScripts.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QRegularExpression \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qregularexpression.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QFileInfo \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qfileinfo.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QTimer \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qtimer.h \
|
||||
../../src/layout/flowlayout/flowLayout.h \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QLayout \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qlayout.h \
|
||||
@@ -1494,7 +1488,9 @@ musicSelector.o: ../../src/windows/musicSelector/musicSelector.cpp ../../src/win
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QDir \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qdir.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QCoreApplication \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qcoreapplication.h
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qcoreapplication.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QFileInfo \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qfileinfo.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o musicSelector.o ../../src/windows/musicSelector/musicSelector.cpp
|
||||
|
||||
playerWindow.o: ../../src/windows/playerWindow/playerWindow.cpp ../../src/windows/playerWindow/playerWindow.h \
|
||||
@@ -1506,20 +1502,26 @@ playerWindow.o: ../../src/windows/playerWindow/playerWindow.cpp ../../src/window
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qmediaplayer.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QAudioOutput \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qaudiooutput.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QTimer \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qtimer.h \
|
||||
../../src/data/albumInformation.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QString \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qstring.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QStringList \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qstringlist.h \
|
||||
../../src/data/cleanerScripts.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QRegularExpression \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qregularexpression.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QFileInfo \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qfileinfo.h \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QVBoxLayout \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qboxlayout.h \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/QPixmap \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/qpixmap.h
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/QPainter \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/qpainter.h \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/QPainterPath \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/qpainterpath.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QFileInfo \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qfileinfo.h \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/QCloseEvent \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/qevent.h \
|
||||
../../src/data/cleanerScripts.h \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/QRegularExpression \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qregularexpression.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o playerWindow.o ../../src/windows/playerWindow/playerWindow.cpp
|
||||
|
||||
albumButton.o: ../../src/components/albumButton/albumButton.cpp ../../src/components/albumButton/albumButton.h \
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,31 +1,100 @@
|
||||
#include "playerWindow.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#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, 350);
|
||||
this->resize(300, 370);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
|
||||
// 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);
|
||||
// --------------------------------------
|
||||
// 1. CREATE ALBUM ART (CIRCULAR)
|
||||
// --------------------------------------
|
||||
artLabel_ = new QLabel;
|
||||
artLabel_->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(artLabel_);
|
||||
|
||||
// Track Label (new)
|
||||
QPixmap pix(item.imagePath);
|
||||
|
||||
// Scale, crop square
|
||||
QPixmap scaled = pix.scaled(250, 250,
|
||||
Qt::KeepAspectRatioByExpanding,
|
||||
Qt::SmoothTransformation);
|
||||
|
||||
int side = qMin(scaled.width(), scaled.height());
|
||||
QPixmap square = scaled.copy(
|
||||
(scaled.width() - side) / 2,
|
||||
(scaled.height() - side) / 2,
|
||||
side,
|
||||
side
|
||||
);
|
||||
|
||||
// Mask to circle
|
||||
discArt_ = QPixmap(side, side);
|
||||
discArt_.fill(Qt::transparent);
|
||||
|
||||
{
|
||||
QPainter p(&discArt_);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse(0, 0, side, side);
|
||||
p.setClipPath(path);
|
||||
|
||||
p.drawPixmap(0, 0, square);
|
||||
}
|
||||
|
||||
artLabel_->setPixmap(discArt_);
|
||||
|
||||
// --------------------------------------
|
||||
// 2. TRACK LABEL
|
||||
// --------------------------------------
|
||||
trackLabel_ = new QLabel("Track 1");
|
||||
trackLabel_->setAlignment(Qt::AlignCenter);
|
||||
trackLabel_->setStyleSheet("font-size: 14px; font-weight: 500;");
|
||||
layout->addWidget(trackLabel_);
|
||||
|
||||
// Player setup
|
||||
// --------------------------------------
|
||||
// 3. SPINNING TIMER
|
||||
// --------------------------------------
|
||||
spinTimer_ = new QTimer(this);
|
||||
spinTimer_->setInterval(16);
|
||||
|
||||
connect(spinTimer_, &QTimer::timeout, this, [this]() {
|
||||
rotationAngle_ += 0.6;
|
||||
|
||||
int side = discArt_.width();
|
||||
QPixmap frame(side, side);
|
||||
frame.fill(Qt::transparent);
|
||||
|
||||
QPainter p(&frame);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
// rotate around center
|
||||
p.translate(side / 2, side / 2);
|
||||
p.rotate(rotationAngle_);
|
||||
p.translate(-side / 2, -side / 2);
|
||||
|
||||
p.drawPixmap(0, 0, discArt_);
|
||||
|
||||
// If you eventually add overlay:
|
||||
// p.resetTransform();
|
||||
// p.drawPixmap(0, 0, overlayArt_);
|
||||
|
||||
artLabel_->setPixmap(frame);
|
||||
});
|
||||
|
||||
// --------------------------------------
|
||||
// 4. MEDIA PLAYER SETUP
|
||||
// --------------------------------------
|
||||
player_ = new QMediaPlayer(this);
|
||||
audio_ = new QAudioOutput(this);
|
||||
player_->setAudioOutput(audio_);
|
||||
@@ -33,10 +102,22 @@ PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
|
||||
connect(player_, &QMediaPlayer::mediaStatusChanged, this,
|
||||
[this](QMediaPlayer::MediaStatus s) {
|
||||
if (s == QMediaPlayer::EndOfMedia) {
|
||||
spinTimer_->stop();
|
||||
playNext();
|
||||
}
|
||||
});
|
||||
|
||||
connect(player_, &QMediaPlayer::playbackStateChanged, this,
|
||||
[this](QMediaPlayer::PlaybackState st) {
|
||||
if (st == QMediaPlayer::PlayingState)
|
||||
spinTimer_->start();
|
||||
else
|
||||
spinTimer_->stop();
|
||||
});
|
||||
|
||||
// --------------------------------------
|
||||
// 5. PLAY FIRST TRACK
|
||||
// --------------------------------------
|
||||
playNext();
|
||||
}
|
||||
|
||||
@@ -49,14 +130,11 @@ void PlayerWindow::playNext()
|
||||
|
||||
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));
|
||||
trackLabel_->setText(
|
||||
QString("Track %1: %2").arg(index_ + 1).arg(title)
|
||||
);
|
||||
|
||||
player_->setSource(QUrl::fromLocalFile(filePath));
|
||||
player_->play();
|
||||
@@ -64,11 +142,11 @@ void PlayerWindow::playNext()
|
||||
index_++;
|
||||
}
|
||||
|
||||
// Stop the music when the window is closed
|
||||
void PlayerWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
if (player_) {
|
||||
player_->stop();
|
||||
spinTimer_->stop();
|
||||
}
|
||||
QWidget::closeEvent(event); // still let Qt do its normal cleanup
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QMediaPlayer>
|
||||
#include <QAudioOutput>
|
||||
#include <QTimer>
|
||||
#include "src/data/albumInformation.h"
|
||||
#include "src/data/cleanerScripts.h"
|
||||
|
||||
class PlayerWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
QLabel* trackLabel_;
|
||||
|
||||
public:
|
||||
explicit PlayerWindow(const AlbumData& item, QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void playNext();
|
||||
|
||||
@@ -22,7 +26,12 @@ private:
|
||||
QMediaPlayer* player_;
|
||||
QAudioOutput* audio_;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
QLabel* artLabel_;
|
||||
QLabel* trackLabel_;
|
||||
|
||||
QPixmap discArt_; // circular cropped album art
|
||||
QPixmap overlayArt_; // optional overlay (not required)
|
||||
qreal rotationAngle_ = 0;
|
||||
|
||||
QTimer* spinTimer_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user