Improve ticker handling to stop recording
This commit is contained in:
parent
426268b512
commit
1e8fe94e3e
|
@ -32,8 +32,8 @@ class Program
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task ConnectWebSocket()
|
||||
{
|
||||
private static async Task ConnectWebSocket()
|
||||
{
|
||||
var tickerUri = new Uri($"ws://{WebsocketAddress}:{WebsocketPort}");
|
||||
var reconnecting = false;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -102,7 +116,8 @@ class Program
|
|||
await Task.Delay(10000);
|
||||
await ConnectWebSocket();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void StartRecording(string songName)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue