diff --git a/src/Controller/MusicPlayer/MusicPlayer.cpp b/src/Controller/MusicPlayer/MusicPlayer.cpp index f6ec244..9a9b23f 100644 --- a/src/Controller/MusicPlayer/MusicPlayer.cpp +++ b/src/Controller/MusicPlayer/MusicPlayer.cpp @@ -87,6 +87,10 @@ bool MusicPlayer::IsPlaying( ) { return audio.IsMusicPaused( ); } +bool MusicPlayer::IsActive( ) { + return audio.IsMusicPlaying( ); +} + QPixmap MusicPlayer::GetAlbumArt( ) { return audio.GetAlbumCover( ); } diff --git a/src/Controller/MusicPlayer/MusicPlayer.h b/src/Controller/MusicPlayer/MusicPlayer.h index 5ac910d..d454801 100644 --- a/src/Controller/MusicPlayer/MusicPlayer.h +++ b/src/Controller/MusicPlayer/MusicPlayer.h @@ -109,11 +109,13 @@ class MusicPlayer : public QObject { this->shuffle = shuffle; shuffleHandler( ); } + bool IsActive( ); bool GetShuffle( ) { return shuffle; } void SetLoop(Loop loop) { this->loop = loop; } Loop GetLoop( ) { return loop; } u_short GetVolume( ) { return audio.GetVolume( ); } void SetVolume(u_short volume) { audio.SetVolume(volume); } + int GetSongDuration( ) { return audio.GetMusicDuration( ); } void AddSongToQueue(Song* song); void RemoveSongFromQueue(Song* song); diff --git a/src/View/Modules/FloatingControls/FloatingControls.cpp b/src/View/Modules/FloatingControls/FloatingControls.cpp index 42e790a..cbb27ba 100755 --- a/src/View/Modules/FloatingControls/FloatingControls.cpp +++ b/src/View/Modules/FloatingControls/FloatingControls.cpp @@ -166,6 +166,7 @@ FloatingControls::FloatingControls(QWidget* parent) : color: #D7D7D7; } )"); + connect(&musicPlayer, &MusicPlayer::SongChanged, this, &FloatingControls::setSongDur); #pragma endregion #pragma region Song Progress Bar @@ -304,6 +305,27 @@ FloatingControls::FloatingControls(QWidget* parent) : mainLayout->setSpacing(10); this->setLayout(mainLayout); + + m_progressUpdateTimer = new QTimer( ); + connect(m_progressUpdateTimer, &QTimer::timeout, this, [this]( ) { + if (!musicPlayer.IsActive( )) { + m_songProgress->setValue(0); + m_songPos->setText("-:--"); + return; + } + + u_short sec = musicPlayer.GetSongProgression( ); + + m_songPos->setText( + QTime( + 0, + sec / 60, + sec % 60 + ).toString("mm:ss")); + + m_songProgress->setValue(sec); + }); + m_progressUpdateTimer->start(1000); } FloatingControls::~FloatingControls( ) { } @@ -412,7 +434,6 @@ void FloatingControls::playPause( ) { } void FloatingControls::setTitle( ) { - std::cout << musicPlayer.GetCurrentlyPlaying( )->GetTitle( ) << std::endl; m_title->setText(QString::fromStdString(musicPlayer.GetCurrentlyPlaying( )->GetTitle( ))); m_artist->setText(QString::fromStdString(musicPlayer.GetCurrentlyPlaying( )->GetArtist( ))); @@ -429,3 +450,14 @@ void FloatingControls::setTitle( ) { m_albumArt->setPixmap(m_albumArt->pixmap( ).copy(targetRect).scaled(QSize(64, 64), Qt::KeepAspectRatio)); } + +void FloatingControls::setSongDur( ) { + u_short sec = musicPlayer.GetSongDuration( ); + + m_songDur->setText( + QTime( + 0, + sec / 60, + sec % 60 + ).toString("mm:ss")); +} diff --git a/src/View/Modules/FloatingControls/FloatingControls.h b/src/View/Modules/FloatingControls/FloatingControls.h index e82799f..fb78785 100755 --- a/src/View/Modules/FloatingControls/FloatingControls.h +++ b/src/View/Modules/FloatingControls/FloatingControls.h @@ -58,6 +58,9 @@ class FloatingControls : public QFrame { QSlider* m_songProgress; QSlider* m_volumeSlider; + // Timer to update the song's duration and slider + QTimer* m_progressUpdateTimer; + bool fullscreen; signals: @@ -70,4 +73,5 @@ private slots: void playPause( ); void setTitle( ); + void setSongDur( ); };