title: Create an InMemory Wav stream and Play it in a UWP app
body: <p>I have an in memory WAV stream that I am able to play using </p>
  
  <pre><code>    mStrm.Seek(0, SeekOrigin.Begin);
      new System.Media.SoundPlayer(mStrm).Play();
  </code></pre>
  
  <p>I am trying to see how i can use the same stream and play it in a UWP application. I tried the following code</p>
  
  <pre><code>        MediaElement soundPlayer = new MediaElement();
          var soundSource = mStrm.AsRandomAccessStream();
          soundSource.Seek(0);
          soundPlayer.SetSource(soundSource, "audio/wav");
          soundPlayer.Play();
  </code></pre>
  
  <p>But I am receiving the following error</p>
  
  <pre><code>    MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0x80000013
  </code></pre>
  
  <p>Adding the code for the audio synthesis that I have taken from web.</p>
  
  <pre><code>    public static void PlayBeep(UInt16 frequency, int msDuration, UInt16    volume = 16383)
      {
          var mStrm = new MemoryStream();
          BinaryWriter writer = new BinaryWriter(mStrm);
  
          const double TAU = 2 * Math.PI;
          int formatChunkSize = 16;
          int headerSize = 8;
          short formatType = 1;
          short tracks = 1;
          int samplesPerSecond = 44100;
          short bitsPerSample = 16;
          short frameSize = (short)(tracks * ((bitsPerSample + 7) / 8));
          int bytesPerSecond = samplesPerSecond * frameSize;
          int waveSize = 4;
          int samples = (int)((decimal)samplesPerSecond * msDuration / 1000);
          int dataChunkSize = samples * frameSize;
          int fileSize = waveSize + headerSize + formatChunkSize + headerSize + dataChunkSize;
          writer.Write(0x46464952);
          writer.Write(fileSize);
          writer.Write(0x45564157);
          writer.Write(0x20746D66);
          writer.Write(formatChunkSize);
          writer.Write(formatType);
          writer.Write(tracks);
          writer.Write(samplesPerSecond);
          writer.Write(bytesPerSecond);
          writer.Write(frameSize);
          writer.Write(bitsPerSample);
          writer.Write(0x61746164); // = encoding.GetBytes("data")
          writer.Write(dataChunkSize);
          {
              double theta = frequency * TAU / (double)samplesPerSecond;
              double amp = volume &gt;&gt; 2;
              for (int step = 0; step &lt; samples; step++)
              {
                  short s = (short)(amp * Math.Sin(theta * (double)step));
                  writer.Write(s);
              }
          }
  
          mStrm.Seek(0, SeekOrigin.Begin);
          MediaElement soundPlayer = new MediaElement();
          var soundSource = mStrm.AsRandomAccessStream();
          soundSource.Seek(0);
          soundPlayer.SetSource(soundSource, "audio/wav");
          soundPlayer.Play();
          writer.Dispose();
          mStrm.Dispose();
      }
  </code></pre>
  
  <p>And I have am passing the different note frequencies for different octaves in a for loop and the duration is 1000milliseconds.</p>
  
  <p>Any help on this is appreciated.</p>
  
  <p>Thanks,
  Teja</p>