Fixed Single-loop mode playing multiple times on fast speeds.

This commit is contained in:
2025-10-29 08:55:36 +02:00
parent 06891e8d82
commit c9f1e8e4ae
2 changed files with 24 additions and 33 deletions

View File

@@ -135,9 +135,13 @@ void Player::stop() {
isPlaying = false;
// Set STOPPING status - actual stop message will be sent when BellEngine finishes
setStatus(PlayerStatus::STOPPING);
LOG_DEBUG("Plbck: SOFT STOP (waiting for melody to complete)");
if (isPaused) {
setStatus(PlayerStatus::STOPPED);
LOG_DEBUG("Plbck: STOP from PAUSED state");
} else {
setStatus(PlayerStatus::STOPPING);
LOG_DEBUG("Plbck: SOFT STOP (waiting for melody to complete)");
}
// NOTE: The actual "stop" message is now sent in onMelodyLoopCompleted()
// when the BellEngine actually finishes the current loop
}
@@ -294,13 +298,7 @@ void Player::durationTimerCallback(TimerHandle_t xTimer) {
// Check if it's time to stop playback
bool Player::timeToStop(unsigned long now) {
if (isPlaying && !infinite_play && total_duration == 0) {
if (now > startTime){}
LOG_DEBUG("(Single Loop Run Seelected) Soft Stopping.");
return true;
}
}
else if (isPlaying && !infinite_play) {
if (isPlaying && !infinite_play) {
uint64_t stopTime = startTime + total_duration;
if (now >= stopTime) {
LOG_DEBUG("(TimerFunction) Total Run Duration Reached. Soft Stopping.");
@@ -374,23 +372,12 @@ void Player::onMelodyLoopCompleted() {
// Check if it's time to pause playback
bool Player::timeToPause(unsigned long now) {
if (isPlaying && continuous_loop) {
// Special case: segment_duration = 0 means "one loop only"
if (segment_duration == 0) {
// Only pause after first loop completes (segmentCmpltTime updated)
if (segmentCmpltTime > segmentStartTime && !isPaused) {
LOG_DEBUG("(TimerFunction) One-loop segment completed. Pausing.");
pauseTime = now;
return true;
}
} else {
// Normal duration-based pausing
uint64_t timeToPause = segmentStartTime + segment_duration;
LOG_DEBUG("PTL: %llu // NOW: %lu", timeToPause, now);
if (now >= timeToPause && !isPaused) {
LOG_DEBUG("(TimerFunction) Segment Duration Reached. Pausing.");
pauseTime = now;
return true;
}
uint64_t timeToPause = segmentStartTime + segment_duration;
LOG_DEBUG("PTL: %llu // NOW: %lu", timeToPause, now);
if (now >= timeToPause && !isPaused) {
LOG_DEBUG("(TimerFunction) Segment Duration Reached. Pausing.");
pauseTime = now;
return true;
}
}
return false;