Have timer run and update progressbar to show playing track state.

This commit is contained in:
Kevin Whitaker
2017-02-16 20:30:05 -05:00
parent 53bc31ebb9
commit b101657669
3 changed files with 37 additions and 2 deletions

View File

@@ -54,7 +54,7 @@ void WebInterface::loginCompleted()
//Login completed, now bring up main inteface. //Login completed, now bring up main inteface.
priv_int->loginUI->animateHide(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade)); 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)); 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) void WebInterface::playPauseActionFromServer(User userPausing, bool pause)
@@ -66,7 +66,7 @@ void WebInterface::playPauseActionFromServer(User userPausing, bool pause)
void WebInterface::songChangedFromServer(AudioTrack nextTrack) void WebInterface::songChangedFromServer(AudioTrack nextTrack)
{ {
//priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change"); priv_int->playerUI->updateDetailsFromServer(nextTrack);
triggerUpdate(); triggerUpdate();
} }

View File

@@ -20,6 +20,7 @@
#include "PlayerInterface.h" #include "PlayerInterface.h"
#include <Wt/WText> #include <Wt/WText>
#include "../GroovePlayer.h" #include "../GroovePlayer.h"
#include <grooveplayer/player.h>
PlayerInterface::PlayerInterface(WebInterface* app) PlayerInterface::PlayerInterface(WebInterface* app)
{ {
@@ -37,6 +38,7 @@ PlayerInterface::PlayerInterface(WebInterface* app)
currentTrackProgress->setFormat(""); currentTrackProgress->setFormat("");
trackProgress = new Wt::WTimer(); trackProgress = new Wt::WTimer();
trackProgress->setInterval(1000); trackProgress->setInterval(1000);
trackProgress->timeout().connect(this,&PlayerInterface::updateProgressFromTimer);
//TODO:track details //TODO:track details
playpause = new Wt::WPushButton(); playpause = new Wt::WPushButton();
playpause->setText(groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist)==1?"Pause":"Resume"); playpause->setText(groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist)==1?"Pause":"Resume");
@@ -73,3 +75,34 @@ void PlayerInterface::playpauseUpdated()
playpause->setText("Pause"); 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();
}

View File

@@ -59,6 +59,8 @@ public:
void playpauseClicked(); void playpauseClicked();
void playpauseUpdated(); void playpauseUpdated();
void updateDetailsFromServer(AudioTrack track);
void updateProgressFromTimer();
}; };
#endif // PLAYERINTERFACE_H #endif // PLAYERINTERFACE_H