diff --git a/src/WebInterface.cpp b/src/WebInterface.cpp index 447eb456afdb8ecb266b9b538b6f5976e1db85a1..a44a7172a06c948cebc675fea65780c8dbab650c 100644 --- a/src/WebInterface.cpp +++ b/src/WebInterface.cpp @@ -126,3 +126,19 @@ std::string WebInterface::getNotificationJs(std::string notificationText) std::string escapedText = std::regex_replace(notificationText,std::regex("\""),"'"); return std::string("function notifyMe(a,b){var c=\"")+escapedText+std::string("\";if('Notification'in window)if('granted'===Notification.permission){new Notification(c)}else'denied'!==Notification.permission&&Notification.requestPermission(function(a){if('granted'===a){new Notification(c)}});else;}"); } + +std::string WebInterface::getProgressNextTrackJs(std::string pgObj, std::string incValue, std::string startVal) +{ + return pgObj+".incrementProgress = function(){if(1!="+pgObj+".isPaused&&'100%'!="+pgObj+".firstChild.style.width){if(parseFloat("+pgObj+".firstChild.style.width)+"+incValue+">=100)return void("+pgObj+".firstChild.style.width='100%');"+pgObj+".firstChild.style.width=parseFloat("+pgObj+".firstChild.style.width)+"+incValue+"+'%',setTimeout("+pgObj+".incrementProgress,1e3)}};"+pgObj+".firstChild.style.width = '"+startVal+"%';"; +} + +std::string WebInterface::getProgressPauseJs(std::string pgObj) +{ + return pgObj+".isPaused = true;"; +} + +std::string WebInterface::getProgressResumeJs(std::string pgObj) +{ + return pgObj+".isPaused = false;"+pgObj+".incrementProgress();"; +} + diff --git a/src/WebInterface.h b/src/WebInterface.h index d4c2f016da6eb12fe2c2d4466577eba55f0d4a2a..84860cc1471461baef70a490f474cfca02e66ca8 100644 --- a/src/WebInterface.h +++ b/src/WebInterface.h @@ -41,6 +41,9 @@ public: void voteNextPollClosedFromServer(AudioTrack winner); void createUser(Wt::Dbo::Session* session, std::string username, std::string rawPassword, bool isAdmin); User currentUser; + std::string getProgressNextTrackJs(std::string pgObj, std::string incValue, std::string startVal); + std::string getProgressResumeJs(std::string pgObj); + std::string getProgressPauseJs(std::string pgObj); private: struct internal; internal* priv_int = 0; diff --git a/src/ui/PlayerInterface.cpp b/src/ui/PlayerInterface.cpp index d6262a15319173118b9ae43c38e09666e70017a6..c2ee05e4f37fa6ba59cfecdf664b3ba88abc86d5 100644 --- a/src/ui/PlayerInterface.cpp +++ b/src/ui/PlayerInterface.cpp @@ -38,9 +38,6 @@ PlayerInterface::PlayerInterface(WebInterface* app) currentTrackProgress = new Wt::WProgressBar(); currentTrackProgress->setFormat(""); - trackProgress = new Wt::WTimer(); - trackProgress->setInterval(1000); - trackProgress->timeout().connect(this,&PlayerInterface::updateProgressFromTimer); currentTrackDetails = new TrackDetails(); currentTrackDetails->setMinimumSize(Wt::WLength(100,Wt::WLength::Pixel),Wt::WLength(100,Wt::WLength::Pixel)); currentTrackDetails->changeBackgroundColor(Wt::WColor("#6FFF6F")); @@ -268,26 +265,13 @@ void PlayerInterface::playpauseUpdated() { skipRequest->setEnabled(false); playpause->setText(Wt::WString::fromUTF8("")); + currentTrackProgress->doJavaScript(app->getProgressPauseJs(currentTrackProgress->jsRef())); } else { if(!GroovePlayerMgr::getInstance()->voteEndedButNotNextTrackYet) skipRequest->setEnabled(true); playpause->setText(Wt::WString::fromUTF8("")); - } -} - -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(); + currentTrackProgress->doJavaScript(app->getProgressResumeJs(currentTrackProgress->jsRef())); } } @@ -296,13 +280,10 @@ void PlayerInterface::updateDetailsFromServer(AudioTrack track) //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); + //currentTrackProgress->setMaximum(track.trackLengthSeconds); + //currentTrackProgress->setValue(secondsIn); isPaused = groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist) == 0; - if(!isPaused) - { - trackProgress->start(); - } + currentTrackProgress->doJavaScript(app->getProgressNextTrackJs(currentTrackProgress->jsRef(),std::to_string(100/track.trackLengthSeconds),std::to_string((100/track.trackLengthSeconds)*secondsIn))); playpauseUpdated(); if(GroovePlayerMgr::getInstance()->currentSkipRequester.size() > 0) { diff --git a/src/ui/PlayerInterface.h b/src/ui/PlayerInterface.h index 669761ae2324ffe0a37040061f516551350b2991..053c28a34e8f0591fe8007c9acb5db6cc981f1ca 100644 --- a/src/ui/PlayerInterface.h +++ b/src/ui/PlayerInterface.h @@ -49,7 +49,6 @@ public: //Play controls TrackDetails* currentTrackDetails; Wt::WProgressBar* currentTrackProgress; - Wt::WTimer* trackProgress; Wt::WHBoxLayout* currentTrackLayout; Wt::WContainerWidget* currentTrackContainer; Wt::WPushButton* playpause; @@ -96,7 +95,6 @@ public: void updateDetailsFromServer(AudioTrack track); void updateVoteableTracksFromServer(std::list tracks); void updateVoteTrackState(); - void updateProgressFromTimer(); void updateSkipRequestedFromServer(); void updateSkipDeniedFromServer(); void updateVotingEnded(AudioTrack winner);