NAudio
NAudio copied to clipboard
After I added an Audio Receiver on my server which receives audio chunks I get this error.
Relevant part:
private async void ReceiveAudioChunk(string data) { byte[] audioBytes = Convert.FromBase64String(data);
if (audioBytes.Length == 0)
{
return;
}
using (MemoryStream stream = new MemoryStream(audioBytes))
{
WaveStream waveStream = new RawSourceWaveStream(stream, new WaveFormat(44100, 1));
using (WaveOutEvent waveOut = new WaveOutEvent())
{
waveOut.DeviceNumber = 0;
waveOut.Init(waveStream);
waveOut.Play();
// Wait for the playback to complete
while (waveOut.PlaybackState == PlaybackState.Playing)
{
await Task.Delay(1);
}
waveOut.Stop();
waveOut.Dispose();
}
}
}
Exception thrown: 'NAudio.MmException' in NAudio.WinMM.dll
The program '[81324] Program.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.
Could it be because of some memory issue maybe
If you want to play chunks as they arrive, I recommend not opening a new WaveOutEvent device every time. Instead, use a BufferedWaveProvider
that is constantly playing and place the received audio into that as it arrives
f you want to play chunks as they arrive, I recommend not opening a new WaveOutEvent device every time. Instead, use a
BufferedWaveProvider
that is constantly playing and place the received audio into that as it arrives
Thanks, it fixed the access error, but how? Also really smooth audio now :)))