R – Windows Mobile App – Play Stream Over MMS Protocol

.netcompact-frameworkmmsstreamingwindows-mobile

NOTE: 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):

Link to Original Question

Now here's the question…

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).

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?

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.


I'm actually not sure how to stream MP3 over http either. I have tried this, but it was unsuccessful:

Some MSDN Article about using WMPLib.dll

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.

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:

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)) > 0)
   {
    fs.Write(buffer, 0, bytesRead);
   }
  }
 }
}

SndPlaySync(tempFilePath, 0);

And here is the DllImport:

[DllImport("aygshell.dll", SetLastError = true)]
private static extern IntPtr SndPlaySync(string Path, uint Flags);

Does anyone have any advice for how to stream the MP3 instead?

Thank you in advance.

Best Solution

When you are using MMS there are two options to the serve your music:

  • install the Windows Media Server and add a publishing point for your music
  • if you have a IIS server, you need to get a WMS plugin that will allow you to stream mp3 over HTTP

Refer to this link.

Note that the above two are the only options currently available to serve media over MMS. If you have some other web server, it will need a plugin like that mentioned above for IIS (not so likely to find).

Once done, the windows media player that comes as part of WinMobile 6.x will be able to tune and play stuff from the server. Nothing required on the client (WinMobile) side.

Related Question