Improve ticker handling to stop recording

This commit is contained in:
Mercurio 2024-09-05 12:55:58 +02:00
parent 426268b512
commit 1e8fe94e3e

View file

@ -42,6 +42,9 @@ class Program
var isRecording = false;
var currentSongName = string.Empty;
// Flag to track if we need to check for "MUSIC SELECT!!"
var shouldCheckForMusicSelect = false;
using var clientWebSocket = new ClientWebSocket();
try
{
@ -91,10 +94,21 @@ class Program
isRecording = true;
}
if (!isRecording || (!message.EndsWith("CLEAR!") && !message.EndsWith("FAILED.."))) continue;
if (isRecording)
{
if (shouldCheckForMusicSelect && message.Contains("MUSIC SELECT!!"))
{
Console.WriteLine("Stopping recording...");
StopRecording(currentSongName);
isRecording = false;
shouldCheckForMusicSelect = false;
}
else if (message.EndsWith("CLEAR!") || message.EndsWith("FAILED.."))
{
// Set the flag to check the next message for "MUSIC SELECT!!"
shouldCheckForMusicSelect = true;
}
}
}
if (reconnecting)
@ -104,6 +118,7 @@ class Program
}
}
private static void StartRecording(string songName)
{
Task.Run(() => StartAudioRecording(songName));