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

Related Questions

Is there a way to play audio obtained from MediaStore through the use of
Is there a way to play video on a webpage with javascript without Flash
Is there any way to play progressive videos that is not safe for streaming
I'm obviously not trying to play full spectrum audio, but is there some way
My boss seems to think there's a way to play audio files via a
I have a ComboBox. Without changing the template, is there a way that I
Is there any way I can play the audio I have as MPMediaItem using
Is there any way to play video in Android App widget.
Is there a way to play a SWF and screen capture it in a
Is there any possible way to PLAY a you tube video on page load

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.