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 67687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:17:56+00:00 2026-05-10T19:17:56+00:00

Is there a way in C# to play audio (for example, MP3) direcly from

  • 0

Is there a way in C# to play audio (for example, MP3) direcly from a System.IO.Stream that for instance was returend from a WebRequest without saving the data temporarily to the disk?


Solution with NAudio

With the help of NAudio 1.3 it is possible to:

  1. Load an MP3 file from a URL into a MemoryStream
  2. Convert MP3 data into wave data after it was completely loaded
  3. Playback the wave data using NAudio‘s WaveOut class

It would have been nice to be able to even play a half loaded MP3 file, but this seems to be impossible due to the NAudio library design.

And this is the function that will do the work:

    public static void PlayMp3FromUrl(string url)     {         using (Stream ms = new MemoryStream())         {             using (Stream stream = WebRequest.Create(url)                 .GetResponse().GetResponseStream())             {                 byte[] buffer = new byte[32768];                 int read;                 while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)                 {                     ms.Write(buffer, 0, read);                 }             }              ms.Position = 0;             using (WaveStream blockAlignedStream =                 new BlockAlignReductionStream(                     WaveFormatConversionStream.CreatePcmStream(                         new Mp3FileReader(ms))))             {                 using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))                 {                     waveOut.Init(blockAlignedStream);                     waveOut.Play();                                             while (waveOut.PlaybackState == PlaybackState.Playing )                                             {                         System.Threading.Thread.Sleep(100);                     }                 }             }         }     } 
  • 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. 2026-05-10T19:17:56+00:00Added an answer on May 10, 2026 at 7:17 pm

    Edit: Answer updated to reflect changes in recent versions of NAudio

    It’s possible using the NAudio open source .NET audio library I have written. It looks for an ACM codec on your PC to do the conversion. The Mp3FileReader supplied with NAudio currently expects to be able to reposition within the source stream (it builds an index of MP3 frames up front), so it is not appropriate for streaming over the network. However, you can still use the MP3Frame and AcmMp3FrameDecompressor classes in NAudio to decompress streamed MP3 on the fly.

    I have posted an article on my blog explaining how to play back an MP3 stream using NAudio. Essentially you have one thread downloading MP3 frames, decompressing them and storing them in a BufferedWaveProvider. Another thread then plays back using the BufferedWaveProvider as an input.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer First, a DataTable has columns, not a data-set. If you… May 11, 2026 at 11:08 am
  • added an answer That's because your resource is an Image, which is a… May 11, 2026 at 11:08 am
  • added an answer In your read function: if (in.fail()) should be: if (… May 11, 2026 at 11:08 am

Related Questions

Is there a way in C# to play audio (for example, MP3) direcly from
Is there a portable, not patent-restricted way to play compressed sound files in C#
Is there a way in C# to: Get all the properties of a class
Is there a way in C# or .NET in general to create an attribute
Is there a way to (ab)use the C preprocessor to emulate namespaces in C
Is there an easy way in C# to read a properties file that has
Is there an easy way in C# to create Ordinals for a number? For
Is there a way to declare a variable as Nullable in c#? struct MyStruct
Is there a way to get notification of date change in c#? I have
Is there a way to get the SearchPath API to not search in c:\windows

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.