Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Best way to play audio file

$
0
0

Okay, I know this sounds like a very easy question to some but I am really stuck here. Indeed, I am building an audio player using Naudio and I have realized that in many tutorials people always show easy ways to get you started. However, in my opinion, they always forget to show how things are actually done in a real application. For example, when playing music with Naudio, I would do something like: 

Void PlayAudioMusic(string FilePath)

{

 using (var ms = File.OpenRead(FilePath))
        using
(var rdr = new Mp3FileReader(ms))
        using
(var wavStream = WaveFormatConversionStream.CreatePcmStream(rdr))
        using
(var baStream = new BlockAlignReductionStream(wavStream))
        using
(var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
       
{
            waveOut
.Init(baStream);
            waveOut
.Play();
           

       
}

}

This is great for testing in a simple console application. This however isn't useful if you're actually building a serious application. For example, what many tutorials never say is for example how to handle the most critical things such as:

  1. Disposing resource and when to do it
  2. The best ways to handle different exceptions
  3. What to do before you pause, stop, rewind or even exit the application
  4. Other stuffs I don't even know exist.

Since I am going through this process and have notice that my application has way too many exceptions thrown, can someone please share like a wrapper class around Naudio that he used to handle this. I am sure this will answer many of the trouble some of us have been going through when trying to use Naudio.

Thanks.


Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>