diff --git a/src/WebInterface.cpp b/src/WebInterface.cpp index 6a2ec9e591799a68aaa04ec038593b6e9eae4cf4..a01539bd3f7bbf8a9dea575e40f210fe05d8fa12 100644 --- a/src/WebInterface.cpp +++ b/src/WebInterface.cpp @@ -54,7 +54,7 @@ void WebInterface::loginCompleted() //Login completed, now bring up main inteface. priv_int->loginUI->animateHide(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade)); priv_int->playerUI->animateShow(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade, Wt::WAnimation::TimingFunction::EaseIn, 500)); - //TODO: request current player state. + priv_int->playerUI->updateDetailsFromServer(GroovePlayerMgr::getInstance()->currentTrack); } void WebInterface::playPauseActionFromServer(User userPausing, bool pause) @@ -66,7 +66,7 @@ void WebInterface::playPauseActionFromServer(User userPausing, bool pause) void WebInterface::songChangedFromServer(AudioTrack nextTrack) { - //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change"); + priv_int->playerUI->updateDetailsFromServer(nextTrack); triggerUpdate(); } diff --git a/src/ui/PlayerInterface.cpp b/src/ui/PlayerInterface.cpp index 6d1015a7d359ae60ed5db613dca0c8f30530106c..21a6559a6706d503e926a76ecbca0683ce306800 100644 --- a/src/ui/PlayerInterface.cpp +++ b/src/ui/PlayerInterface.cpp @@ -20,6 +20,7 @@ #include "PlayerInterface.h" #include #include "../GroovePlayer.h" +#include PlayerInterface::PlayerInterface(WebInterface* app) { @@ -37,6 +38,7 @@ PlayerInterface::PlayerInterface(WebInterface* app) currentTrackProgress->setFormat(""); trackProgress = new Wt::WTimer(); trackProgress->setInterval(1000); + trackProgress->timeout().connect(this,&PlayerInterface::updateProgressFromTimer); //TODO:track details playpause = new Wt::WPushButton(); playpause->setText(groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist)==1?"Pause":"Resume"); @@ -73,3 +75,34 @@ void PlayerInterface::playpauseUpdated() playpause->setText("Pause"); } } + +void PlayerInterface::updateProgressFromTimer() +{ + if(currentTrackProgress->maximum() >= currentTrackProgress->value()+1) + { + double secondsIn; + groove_player_position(GroovePlayerMgr::getInstance()->currentPlayer,nullptr, &secondsIn); + currentTrackProgress->setValue(secondsIn); + } + else if(currentTrackProgress->maximum() < currentTrackProgress->value()+1) + { + currentTrackProgress->setValue(currentTrackProgress->maximum()); + trackProgress->stop(); + } +} + +void PlayerInterface::updateDetailsFromServer(AudioTrack track) +{ + //TODO: request current player state. + //Find current song playing and set progress state. + double secondsIn; + groove_player_position(GroovePlayerMgr::getInstance()->currentPlayer,nullptr, &secondsIn); + currentTrackProgress->setMaximum(track.trackLengthSeconds); + currentTrackProgress->setValue(secondsIn); + isPaused = groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist) == 0; + if(!isPaused) + { + trackProgress->start(); + } + playpauseUpdated(); +} diff --git a/src/ui/PlayerInterface.h b/src/ui/PlayerInterface.h index 1c5731584a777bb237f9ca856184b86631f768d6..0c64d4737be536b65c1260b341ca830c852219dc 100644 --- a/src/ui/PlayerInterface.h +++ b/src/ui/PlayerInterface.h @@ -59,6 +59,8 @@ public: void playpauseClicked(); void playpauseUpdated(); + void updateDetailsFromServer(AudioTrack track); + void updateProgressFromTimer(); }; #endif // PLAYERINTERFACE_H