diff --git a/cspot/include/SpircHandler.h b/cspot/include/SpircHandler.h index 33727608..7d558cd8 100644 --- a/cspot/include/SpircHandler.h +++ b/cspot/include/SpircHandler.h @@ -53,6 +53,7 @@ class SpircHandler { bool nextSong(); void notifyAudioReachedPlayback(); + void notifyAudioEnded(); void updatePositionMs(uint32_t position); void setRemoteVolume(int volume); void loadTrackFromURI(const std::string& uri); diff --git a/cspot/src/SpircHandler.cpp b/cspot/src/SpircHandler.cpp index e2f2045b..cd5da7a6 100644 --- a/cspot/src/SpircHandler.cpp +++ b/cspot/src/SpircHandler.cpp @@ -77,6 +77,12 @@ void SpircHandler::subscribeToMercury() { void SpircHandler::loadTrackFromURI(const std::string& uri) {} +void SpircHandler::notifyAudioEnded() { + playbackState->updatePositionMs(0); + notify(); + trackPlayer->resetState(true); +} + void SpircHandler::notifyAudioReachedPlayback() { int offset = 0; diff --git a/targets/cli/CliPlayer.cpp b/targets/cli/CliPlayer.cpp index 2ef17807..4c3ddd99 100644 --- a/targets/cli/CliPlayer.cpp +++ b/targets/cli/CliPlayer.cpp @@ -66,8 +66,12 @@ CliPlayer::CliPlayer(std::unique_ptr sink, break; case cspot::SpircHandler::EventType::PLAYBACK_START: this->isPaused = true; + this->playlistEnd = false; this->centralAudioBuffer->clearBuffer(); break; + case cspot::SpircHandler::EventType::DEPLETED: + this->playlistEnd = true; + break; default: break; } @@ -102,6 +106,10 @@ void CliPlayer::runTask() { } if (!chunk || chunk->pcmSize == 0) { + if (this->playlistEnd) { + this->handler->notifyAudioEnded(); + this->playlistEnd = false; + } BELL_SLEEP_MS(10); continue; } else { diff --git a/targets/cli/CliPlayer.h b/targets/cli/CliPlayer.h index 64c93740..0857a640 100644 --- a/targets/cli/CliPlayer.h +++ b/targets/cli/CliPlayer.h @@ -37,6 +37,7 @@ class CliPlayer : public bell::Task { std::atomic isPaused = true; std::atomic isRunning = true; std::mutex runningMutex; + std::atomic playlistEnd = false; void runTask() override; };