title: How to read or write MP4 file from file stream in silverlight and vb.net application?
body: <p>In my Silverlight web application,I am accessing mp4 audio file from client bin folder.I am saving this file stream to local folder on client machine using save file dialog box.
  I can play mp4 file in media element and can hear audio without any problem,But when I save file to local folder and try to open it,it does not play.
  If I download mp3 file with same way,I can play mp3 audio after download without any issues.<br>
  Is there any different way to read and write stream for mp4 file than mp3.
  No where I found the solution for this.
  Whatever I understood from research till now is , mp4 has moov and mdat box,where mdat comes first.but while reading or writing MP4 files we need to move the moov box ahead of the mdat box, and rewriting file offsets accordingly.
  But I need some example how exactly to read and write mp4 files.</p>
  
  <p>Here is my code</p>
  
  <pre><code>saveFileDialog1.Filter = "MP3 Files (*.mp3)|*.mp3|MP4 Files|*.mp4"
          saveFileDialog1.ShowDialog()
          Dim str As Stream = Nothing
          Using audiofs As System.IO.FileStream = saveFileDialog1.OpenFile()
              Dim bytes As Byte() = New Byte(1638) {}
              Dim bytesToRead As Integer = 0
              bytesToRead = streamAudio_download.Read(bytes, 0, bytes.Length)
              While (bytesToRead = streamAudio_download.Read(bytes, 0, bytes.Length)) &lt;&gt; 0
                  audiofs.Write(bytes, 0, bytesToRead)
              End While
          End Using
  </code></pre>