Answer the question
In order to leave comments, you need to log in
How to make the received sound play continuously, like in a voice chat?
There is such a code written using sockets and NAudio
public void BeginReceive()
{
Thread ReceiveVoiceFromChatThread = new Thread(()=>
{
while (true)
{
try
{
byte[] ReceivedVoiceDataLenght = new byte[4];
VoiceSocket.Receive(ReceivedVoiceDataLenght);
byte[] ReceivedVoiceData = new byte[BitConverter.ToInt32(ReceivedVoiceDataLenght)];
VoiceSocket.Receive(ReceivedVoiceData);
new Thread(() =>
{
try
{
IWaveProvider provider = new RawSourceWaveStream(new MemoryStream(ReceivedVoiceData), new WaveFormat(44100, 1));
WaveOut _waveOut = new();
_waveOut.Init(provider);
_waveOut.Play();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}).Start();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
});
ReceiveVoiceFromChatThread.Start();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question