Skip to content

Commit

Permalink
Fix webstream playlist abort when track fails
Browse files Browse the repository at this point in the history
When the webstream connects but is redirected to a 404 page, we should not abort the playlist but jump to the next entry.
  • Loading branch information
laszloh committed Dec 7, 2023
1 parent 377dc83 commit 0626f80
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void AudioPlayer_Init(void) {
xTaskCreatePinnedToCore(
AudioPlayer_Task, /* Function to implement the task */
"mp3play", /* Name of the task */
6000, /* Stack size in words */
8192, /* Stack size in words */
NULL, /* Task input parameter */
2 | portPRIVILEGE_BIT, /* Priority of the task */
&AudioTaskHandle, /* Task handle. */
Expand Down Expand Up @@ -352,7 +352,9 @@ void AudioPlayer_Task(void *parameter) {
audio->setI2SCommFMT_LSB(true);
#endif

uint8_t settleCount = 0;
constexpr uint32_t playbackTimeout = 2000;
uint32_t playbackTimeoutStart = 0;

AudioPlayer_CurrentVolume = AudioPlayer_GetInitVolume();
audio->setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio->setVolume(AudioPlayer_CurrentVolume, VOLUMECURVE);
Expand Down Expand Up @@ -832,15 +834,16 @@ void AudioPlayer_Task(void *parameter) {
}

if (audio->isRunning()) {
settleCount = 0;
playbackTimeoutStart = millis();
}

// If error occured: remove playlist from ESPuino
// If error occured: move to the next track in the playlist
if (gPlayProperties.playMode != NO_PLAYLIST && gPlayProperties.playMode != BUSY && !audio->isRunning() && !gPlayProperties.pausePlay) {
if (settleCount++ == 50) { // Hack to give audio some time to settle down after playlist was generated
gPlayProperties.playlistFinished = true;
gPlayProperties.playMode = NO_PLAYLIST;
settleCount = 0;
if ((millis() - playbackTimeoutStart) > playbackTimeout) {
// Audio playback timed out, move on to the next
System_IndicateError();
gPlayProperties.trackFinished = true;
playbackTimeoutStart = millis();
}
}
if ((System_GetOperationMode() == OPMODE_BLUETOOTH_SOURCE) && audio->isRunning()) {
Expand Down

0 comments on commit 0626f80

Please sign in to comment.