Skip to content

Commit a5091aa

Browse files
committed
SnapOutput added isActvie()
1 parent 0f282f0 commit a5091aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/api/SnapOutput.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class SnapOutput : public AudioInfoSupport {
123123
// writes the audio data to the decoder
124124
size_t audioWrite(const void *src, size_t size) {
125125
ESP_LOGD(TAG, "%zu", size);
126+
time_last_write = millis();
126127
size_t result = decoder_stream.write((const uint8_t *)src, size);
127128

128129
return result;
@@ -160,6 +161,15 @@ class SnapOutput : public AudioInfoSupport {
160161
return result;
161162
}
162163

164+
uint64_t getLastWriteTime() {
165+
return time_last_write;
166+
}
167+
168+
/// checks if the audio is still playing
169+
bool isActive(uint16_t timeout=1000){
170+
return (time_last_write + timeout) >= millis();
171+
}
172+
163173
protected:
164174
const char *TAG = "SnapOutput";
165175
AudioOutput *out = nullptr;
@@ -175,6 +185,7 @@ class SnapOutput : public AudioInfoSupport {
175185
SnapTimeSync *p_snap_time_sync = nullptr;
176186
bool is_sync_started = false;
177187
bool is_audio_begin_called = false;
188+
uint64_t time_last_write = 0;
178189

179190
/// setup of all audio objects
180191
bool audioBegin() {

0 commit comments

Comments
 (0)