Add song title to current playing screen
This commit is contained in:
@@ -23,6 +23,7 @@ SOURCES += \
|
||||
# ----------------------------------------------------
|
||||
HEADERS += \
|
||||
src/components/albumTile/albumtile.h \
|
||||
src/data/cleanerScripts.h \
|
||||
src/windows/musicSelector/musicSelector.h \
|
||||
src/windows/playerWindow/playerWindow.h \
|
||||
src/components/albumButton/albumButton.h \
|
||||
|
||||
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.
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.
File diff suppressed because one or more lines are too long
@@ -450,6 +450,7 @@ DIST = /opt/homebrew/share/qt/mkspecs/features/spec_pre.prf \
|
||||
/opt/homebrew/share/qt/mkspecs/features/yacc.prf \
|
||||
/opt/homebrew/share/qt/mkspecs/features/lex.prf \
|
||||
../../../../Music-Player.pro ../../src/components/albumTile/albumtile.h \
|
||||
../../src/data/cleanerScripts.h \
|
||||
../../src/windows/musicSelector/musicSelector.h \
|
||||
../../src/windows/playerWindow/playerWindow.h \
|
||||
../../src/components/albumButton/albumButton.h \
|
||||
@@ -1271,7 +1272,7 @@ distdir: FORCE
|
||||
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
|
||||
$(COPY_FILE) --parents qmake_qmake_qm_files.qrc $(DISTDIR)/
|
||||
$(COPY_FILE) --parents /opt/homebrew/share/qt/mkspecs/features/data/dummy.cpp $(DISTDIR)/
|
||||
$(COPY_FILE) --parents ../../src/components/albumTile/albumtile.h ../../src/windows/musicSelector/musicSelector.h ../../src/windows/playerWindow/playerWindow.h ../../src/components/albumButton/albumButton.h ../../src/components/mediaButton/mediaButton.h ../../src/data/albumInformation.h ../../src/layout/flowLayout/flowLayout.h $(DISTDIR)/
|
||||
$(COPY_FILE) --parents ../../src/components/albumTile/albumtile.h ../../src/data/cleanerScripts.h ../../src/windows/musicSelector/musicSelector.h ../../src/windows/playerWindow/playerWindow.h ../../src/components/albumButton/albumButton.h ../../src/components/mediaButton/mediaButton.h ../../src/data/albumInformation.h ../../src/layout/flowLayout/flowLayout.h $(DISTDIR)/
|
||||
$(COPY_FILE) --parents ../../src/components/albumTile/albumtile.cpp ../../src/main.cpp ../../src/windows/musicSelector/musicSelector.cpp ../../src/windows/playerWindow/playerWindow.cpp ../../src/components/albumButton/albumButton.cpp ../../src/components/mediaButton/mediaButton.cpp ../../src/layout/flowLayout/flowLayout.cpp $(DISTDIR)/
|
||||
$(COPY_FILE) --parents ../../src/windows/musicSelector/musicSelector.ui $(DISTDIR)/
|
||||
|
||||
@@ -1353,6 +1354,8 @@ moc_musicSelector.cpp: ../../src/windows/musicSelector/musicSelector.h \
|
||||
moc_playerWindow.cpp: ../../src/windows/playerWindow/playerWindow.h \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QWidget \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qwidget.h \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QLabel \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qlabel.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QMediaPlayer \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qmediaplayer.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QAudioOutput \
|
||||
@@ -1362,6 +1365,11 @@ moc_playerWindow.cpp: ../../src/windows/playerWindow/playerWindow.h \
|
||||
/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
|
||||
@@ -1471,6 +1479,11 @@ 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 \
|
||||
../../src/layout/flowlayout/flowLayout.h \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QLayout \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qlayout.h \
|
||||
@@ -1481,14 +1494,14 @@ 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/QFileInfo \
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qfileinfo.h
|
||||
/opt/homebrew/lib/QtCore.framework/Headers/qcoreapplication.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 \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QWidget \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qwidget.h \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/QLabel \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qlabel.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QMediaPlayer \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/qmediaplayer.h \
|
||||
/opt/homebrew/lib/QtMultimedia.framework/Headers/QAudioOutput \
|
||||
@@ -1498,10 +1511,13 @@ playerWindow.o: ../../src/windows/playerWindow/playerWindow.cpp ../../src/window
|
||||
/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/QtWidgets.framework/Headers/QLabel \
|
||||
/opt/homebrew/lib/QtWidgets.framework/Headers/qlabel.h \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/QPixmap \
|
||||
/opt/homebrew/lib/QtGui.framework/Headers/qpixmap.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o playerWindow.o ../../src/windows/playerWindow/playerWindow.cpp
|
||||
|
||||
Binary file not shown.
@@ -7,6 +7,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../../src/windows/playerWindow/playerWindow.h"
|
||||
#include <QtGui/qtextcursor.h>
|
||||
#include <QtCore/qmetatype.h>
|
||||
|
||||
#include <QtCore/qtmochelpers.h>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
src/data/cleanerScripts.h
Normal file
30
src/data/cleanerScripts.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QRegularExpression>
|
||||
#include <QFileInfo>
|
||||
|
||||
// Cleans track filenames like:
|
||||
// "01 - Speak_To_Me.flac" → "Speak To Me"
|
||||
// "03.Breathe.mp3" → "Breathe"
|
||||
// "7 Time.m4a" → "Time"
|
||||
static inline QString cleanTrackTitle(const QString& fileName)
|
||||
{
|
||||
QString title = fileName;
|
||||
|
||||
// Strip extension
|
||||
int dotIndex = title.lastIndexOf('.');
|
||||
if (dotIndex > 0)
|
||||
title = title.left(dotIndex);
|
||||
|
||||
// Remove leading digits + junk like "-", "_", ".", spaces
|
||||
title.remove(QRegularExpression(R"(^\s*\d+\s*[-_\.]*\s*)"));
|
||||
|
||||
// Replace underscores with spaces
|
||||
title.replace("_", " ");
|
||||
|
||||
// Trim whitespace
|
||||
title = title.trimmed();
|
||||
|
||||
return title;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QMediaPlayer>
|
||||
#include <QAudioOutput>
|
||||
#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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user