Skip to content

Commit

Permalink
add mechanism to end last track properly
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Oct 7, 2023
1 parent 691041e commit babe2e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions cspot/include/SpircHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions cspot/src/SpircHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions targets/cli/CliPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ CliPlayer::CliPlayer(std::unique_ptr<AudioSink> 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;
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions targets/cli/CliPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CliPlayer : public bell::Task {
std::atomic<bool> isPaused = true;
std::atomic<bool> isRunning = true;
std::mutex runningMutex;
std::atomic<bool> playlistEnd = false;

void runTask() override;
};

0 comments on commit babe2e9

Please sign in to comment.