I'm making a small application that receive data from another application and play the sound it receives parts by parts.
This is the simulation I'm doing:
var soundPlayer = new SoundPlayer();
var buffer = new byte[2048];
using (var fileStream = File.OpenRead(filePath))
{
var iOffset = 0;
while (true)
{
try
{
iOffset = fileStream.Read(buffer, iOffset, buffer.Length);
if (iOffset == 0)
{
Console.WriteLine("Offset end.");
break;
}
var memoryStream = new MemoryStream(buffer, 0, buffer.Length);
soundPlayer.Stream = memoryStream;
//soundPlayer.Load();
soundPlayer.Play();
Thread.Sleep(TimeSpan.FromSeconds(10));
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
break;
}
}
It reads a file to memory stream parts by parts (2048 bytes per 5 seconds - connection delay simulation)
The application crashes without jumping into exception code block after soundPlayer.Play()
method.
What wrong am I doing ?
Can anyone help me please ?
Thanks,