From f58679983e0854e2f976f2c5bbea1a8755c70bc3 Mon Sep 17 00:00:00 2001 From: ailurux Date: Fri, 13 Sep 2024 15:23:03 +1000 Subject: [PATCH] Save positions over 5 minutes, every minute --- src/tangara/audio/audio_fsm.cpp | 12 ++++++++++-- src/tangara/audio/audio_fsm.hpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp index 131e0a06..210f9afd 100644 --- a/src/tangara/audio/audio_fsm.cpp +++ b/src/tangara/audio/audio_fsm.cpp @@ -70,6 +70,8 @@ StreamCues AudioState::sStreamCues; bool AudioState::sIsPaused = true; +uint8_t AudioState::sUpdateCounter = 0; + auto AudioState::emitPlaybackUpdate(bool paused) -> void { std::optional position; auto current = sStreamCues.current(); @@ -80,8 +82,14 @@ auto AudioState::emitPlaybackUpdate(bool paused) -> void { current.first->start_offset.value_or(0); } - if (position) { - // Update position if the duration has been long enough + // If we've got an elapsed duration and it's more than 5 minutes + // increment a counter. Every 60 counts (ie, every minute) save the current elapsed position + if (position && *position > (5 * 60)) { + sUpdateCounter++; + if (sUpdateCounter > 60) { + sUpdateCounter = 0; + updateSavedPosition(current.first->uri, *position); + } } PlaybackUpdate event{ diff --git a/src/tangara/audio/audio_fsm.hpp b/src/tangara/audio/audio_fsm.hpp index 0c8f4d26..99824b4c 100644 --- a/src/tangara/audio/audio_fsm.hpp +++ b/src/tangara/audio/audio_fsm.hpp @@ -90,6 +90,7 @@ class AudioState : public tinyfsm::Fsm { static std::optional sDrainFormat; static bool sIsPaused; + static uint8_t sUpdateCounter; }; namespace states {