From 32b41a6b0e7fa9b5a764b820752d4381b25d3ba2 Mon Sep 17 00:00:00 2001 From: isp Date: Tue, 10 Sep 2024 19:30:49 -0700 Subject: [PATCH] Bump --- .../identify/presentation/SoundRecorder.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wear/src/main/java/com/birdsounds/identify/presentation/SoundRecorder.kt b/wear/src/main/java/com/birdsounds/identify/presentation/SoundRecorder.kt index 99c2e4a..0a7c620 100644 --- a/wear/src/main/java/com/birdsounds/identify/presentation/SoundRecorder.kt +++ b/wear/src/main/java/com/birdsounds/identify/presentation/SoundRecorder.kt @@ -52,6 +52,12 @@ class SoundRecorder( val thread = Thread { while (true) { + if (Thread.interrupted()) { + // check for the interrupted flag, reset it, and throw exception + Log.w(TAG,"Finished thread"); + break; + } + Log.w(TAG,"Loop"); val out = audioRecord.read( /* audioData = */ audio_bytes_array, /* offsetInBytes = */ 0, @@ -64,13 +70,20 @@ class SoundRecorder( // Log.w(TAG, audio_bytes_array.size.toString()); val str_beg = audio_bytes_array[0].toString() val str_end = audio_bytes_array[bufferSizeInBytes-1].toString() - Log.w(TAG, str_beg + ", " + str_end); +// Log.w(TAG, str_beg + ", " + str_end); // MessageSender.sendMessage("/audio",audio_bytes_array, context) } }; thread.start(); + cont.invokeOnCancellation { + audioRecord.stop(); + audioRecord.release() + thread.interrupt(); + state = State.IDLE + } + } }