title: Is there any way to convert .mp4 format audio to .wav format just in memory?
body: <p>I'm developing a WPF application, where I have to play audio. I receive the audio data in <code>.mp4</code> format (in a byte array) and the only restriction is that I can't write it out to the hard disk.</p>
  
  <p>I found couple of solutions for playing the <code>.mp4</code> format, for example with <code>WMPLib.WindowsMediaPlayer</code>, but I can't give a byte array, or stream to this library, to play the audio. It just accepts the file path.</p>
  
  <p>Then I found the <code>System.Media.SoundPlayer</code>, which can play audio from a stream, but just in <code>.wav</code> format. I started to search for solutions to convert from mp4 to wav. I found the <code>NAudio</code> library and I could make the conversion the following way:</p>
  
  <pre><code>using (var data = new MediaFoundationReader(filePath)) {
    var stream = new MemoryStream();
    WaveFileWriter.WriteWavFileToStream(stream, data);
  }
  </code></pre>
  
  <p>The problem with this is that I can instantiate the <code>MediaFoundationReader</code> just with a file path parameter. I didn't find any way to create it without using files. I think this was also a dead end.</p>
  
  <p>So, any suggestion would be helpful about how can I convert audio in memory, or maybe how can I play directly the <code>.mp4</code> file from a byte array or stream?</p>