Question

In C# I want to record an audio stream

I am doing something along the lines of:

HttpWebRequest req;
req = (HttpWebRequest)WebRequest.Create("http://url.com/stream");

Webresponse resp = req.GetResponse();
Stream s = resp.GetResponseStream();

fs = File.Exists(fileName)
    ? new FileStream(fileName, FileMode.Append)
    : new FileStream(fileName, FileMode.Create);

byte[] buffer = new byte[4096];

while (s.CanRead)
{
    Array.Clear(buffer, 0, buffer.Length);
    total += s.Read(buffer, 0, buffer.Length);
    fs.Write(buffer, 0, buffer.Length);
}

and the file size grows but can't be played back by VLC or any other program.

This is not my exact code I do a lot of error checking etc, but this gives the general idea.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top