Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4594142
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:47:10+00:00 2026-05-21T22:47:10+00:00

In C# I want to record an audio stream I am doing something along

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:47:10+00:00Added an answer on May 21, 2026 at 10:47 pm
        Array.Clear(buffer, 0, buffer.Length);
        total += s.Read(buffer, 0, buffer.Length);
        fs.Write(buffer, 0, buffer.Length);
    

    You do not have to clear the whole array before you read – there’s no point in doing this. But you have to check how many bytes you actually read, there’s no guarantee the whole array is filled every time (and it probably won’t):

        int bytesRead = s.Read(buffer, 0, buffer.Length);
        fs.Write(buffer, 0, bytesRead);
        total+=bytesRead;
    

    Also whether the file plays (even when it is not corrupted anymore once you fix the file writing code) back depends on the format that you are downloading – what codec / file type is it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to record audio stream as mp3 file on server. I know flash
I want to make a program that would record audio data using PortAudio (I
I m using a microphone class to record audio from user. I want to
I want the user to be able to record audio in an app, and
I want to record the audio continuously and send it to a device on
I want to record the live audio and play it.As far as UI is
Is it possible to record audio only when there is someone talking? I want
I want to record audio using javascript and html5, there is device element in
I want to Record audio but with some background images in out put file.
I am recording audio using AudioRecord class.I want to record audio into a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.