title: How to play non buffered WAV with MediaStreamSource implementation in Silverlight 4?
body: <p><strong>Background</strong></p>
  <p>I'm trying to stream a wave file in Silverlight 4 using MediaStreamSource implementation found <a href="https://docs.microsoft.com/en-us/archive/blogs/gillesk/playing-back-wave-files-in-silverlight" rel="nofollow noreferrer">here</a>. The problem is I want to play the file while it's still buffering, or at least give user some visual feedback while it's buffering. For now my code looks like that:</p>
  <pre><code>private void button1_Click(object sender, RoutedEventArgs e)
  {
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(App.Current.Host.Source, &quot;../test.wav&quot;));
      //request.ContentType = &quot;audio/x-wav&quot;;
      request.AllowReadStreamBuffering = false;
      
      request.BeginGetResponse(new AsyncCallback(RequestCallback), request);
  }
  
  private void RequestCallback(IAsyncResult ar)
  {
      this.Dispatcher.BeginInvoke(delegate()
      {
          HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
          HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar);
  
          WaveMediaStreamSource wavMss = new WaveMediaStreamSource(response.GetResponseStream());
          
          try
          {
              me.SetSource(wavMss);
          }
          catch (InvalidOperationException)
          {
              // This file is not valid
          }
          me.Play();
      });
  }
  </code></pre>
  <p>The problem is that after setting <code>request.AllowReadStreamBuffering = false</code> the stream does not support seeking and the above mentioned implementation throws an exception (keep in mind I've put some of the position setting logic into <code>if (stream.CanSeek)</code> block):</p>
  <blockquote>
  <p>Read is not supported on the main thread when buffering is disabled</p>
  </blockquote>
  <p><strong>Question</strong></p>
  <p>Is there a way to play WAV stream without buffering it in advance in Silverlight 4?</p>