Have timer run and update progressbar to show playing track state.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "PlayerInterface.h"
|
||||
#include <Wt/WText>
|
||||
#include "../GroovePlayer.h"
|
||||
#include <grooveplayer/player.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user