Skip to content

Commit

Permalink
Fixed progress bar not showing after a page refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
CelliesProjects committed Feb 10, 2023
1 parent a76dc3d commit 6fd915f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eStreamPlayer32_VS1053.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static const char* MESSAGE_HEADER = "message";
static const char* CURRENT_HEADER = "currentPLitem";

static auto _playerVolume = VS1053_INITIALVOLUME;
static size_t _currentPosition = 0;
static size_t _currentSize = 0;
static bool _paused = false;

constexpr const auto NUMBER_OF_PRESETS = sizeof(preset) / sizeof(source);
Expand Down Expand Up @@ -68,13 +70,16 @@ void playerTask(void* parameter) {
ws.textAll("status\nplaying\n");
if (!audio.connecttohost(msg.url, LIBRARY_USER, LIBRARY_PWD, msg.value))
startNextItem();
_currentSize = audio.size();
_currentPosition = audio.position();
break;
case playerMessage::STOPSONG:
audio.stopSong();
break;
default: log_e("error: unhandled audio action: %i", msg.action);
}
}

constexpr const auto MAX_UPDATE_FREQ_HZ = 6;
constexpr const auto UPDATE_INTERVAL_MS = 1000 / MAX_UPDATE_FREQ_HZ;
static unsigned long previousTime = millis();
Expand All @@ -83,6 +88,7 @@ void playerTask(void* parameter) {
ws.printfAll("progress\n%i\n%i\n", audio.position(), audio.size());
previousTime = millis();
previousPosition = audio.position();
_currentPosition = audio.position();
}
audio.loop();
}
Expand Down
1 change: 1 addition & 0 deletions websocketEventHandler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void websocketEventHandler(AsyncWebSocket* server, AsyncWebSocketClient* client,
client->printf("%s\n%i\n", VOLUME_HEADER, _playerVolume);
client->text(showstation);
client->text(streamtitle);
if (_paused && _currentSize) client->printf("progress\n%i\n%i\n", _currentPosition, _currentSize);
}
break;
case WS_EVT_DISCONNECT:
Expand Down

0 comments on commit 6fd915f

Please sign in to comment.