title: Wave Header corrupted
body: <p>I want to do some changing on Wave file, then Play it Directly after doing that.</p>
  
  <p>So I define a byte array to store the bytes of wave file on it as following:</p>
  
  <pre><code>byte[] byteArr;
  byteArr = File.ReadAllBytes(dlg.FileName);
  </code></pre>
  
  <p>where dlg is an OpenFile Dialog.</p>
  
  <p>Then I do a changing to sample bit rate of wave as following:</p>
  
  <pre><code>private void playSlectedWave_Click(object sender, EventArgs e)
  {
      int sample = 50000;
      MemoryStream fs = new MemoryStream(byteArr);
      BinaryReader br = new BinaryReader(fs);
      int length = (int)fs.Length-8;
      fs.Position = 22;
      short channels = br.ReadInt16();
      fs.Position = 34;
      short BitsPerSample = br.ReadInt16();
      byte[] arrfile = new byte[fs.Length];
      fs.Position = 0;
      fs.Read(arrfile, 0, arrfile.Length);
      BinaryWriter bw = new BinaryWriter(fs);
      bw.BaseStream.Seek(0, SeekOrigin.Begin);
      bw.Write(arrfile, 0, 24); 
      bw.Write(sample);
      bw.Write((int)(sample* ((BitsPerSample * channels) / 8)));
      bw.Write((short)((BitsPerSample * channels) / 8));
      bw.Write(arrfile, 34, arrfile.Length - 34);
      SoundPlayer SP = new SoundPlayer(fs);
      SP.Play();
  }
  </code></pre>
  
  <p>My question is that when it reaches the <code>SP.Play()</code> it throws an exception that says that the Wave Header is corrupted.</p>
  
  <p>For more Information, I try the previous code but with FileStream instead of MemoryStream and it works fine for me .</p>
  
  <p>Does Anyone know why?</p>