title: Windows Mobile App - Play Stream Over MMS Protocol?
body: <p><strong>NOTE:</strong> This question is being reasked because I accidentally clicked Community Wiki in the previous one, and obviously that didn't provide enough incentive in the form of reputation for people to answer it.  Here is a link to the old question, please do not duplicate those answers (they weren't exactly helpful anyway):</p>
  
  <p><a href="https://stackoverflow.com/questions/1106947/windows-mobile-app-play-mms-stream">Link to Original Question</a></p>
  
  <p>Now here's the question...</p>
  
  <p>I'm trying to write a Windows Mobile app targeting Windows Mobile 6.x that will stream an internet radio stream delivered via MMS protocol (just one feature among other things).</p>
  
  <p>Does the .NET Compact Framework have built-in controls or API's that will do this? Or would I need to start looking for a third-party library?</p>
  
  <p>I'm a little confused why this wouldn't be supported in the .NET Compact Framework? I mean MMS is Microsoft's proprietary Windows streaming protocol.</p>
  
  <hr>
  
  <p>I'm actually not sure how to stream MP3 over http either. I have tried this, but it was unsuccessful:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/dd562692(VS.85).aspx" rel="nofollow noreferrer">Some MSDN Article about using WMPLib.dll</a></p>
  
  <p>In fact, it is unsuccessful if I navigate to the mobile's Windows Media Player itself and give it the same URL I am trying to stream programmatically. However, this same URL does work from the Windows Media Player on my desktop computer.  And yes, it is typed in correctly.</p>
  
  <p>I have actually come across another idea to play an MP3 file on Windows Mobile in my custom app, but it doesn't have the ability to stream on the fly.  Instead it downloads the entirety of the file before playing it on the mobile device.  Here is some code:</p>
  
  <pre><code>string url = @"http://blahblah.com/blahblah.mp3";
  string tempFilePath = Path.GetTempPath() + "tempFile.mp3";
  
  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  {
   byte[] buffer = new byte[1024];
   int bytesRead = 0;
  
   using (Stream responseStream = response.GetResponseStream())
   {
    using (FileStream fs = new FileStream(tempFilePath, FileMode.Create, FileAccess.ReadWrite))
    {
     while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) &gt; 0)
     {
      fs.Write(buffer, 0, bytesRead);
     }
    }
   }
  }
  
  SndPlaySync(tempFilePath, 0);
  </code></pre>
  
  <p>And here is the DllImport:</p>
  
  <pre><code>[DllImport("aygshell.dll", SetLastError = true)]
  private static extern IntPtr SndPlaySync(string Path, uint Flags);
  </code></pre>
  
  <p>Does anyone have any advice for how to stream the MP3 instead?</p>
  
  <p>Thank you in advance.</p>