Techniques - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Techniques arrow Streaming with Windows Media Services and ASP.NET
Streaming with Windows Media Services and ASP.NET
By Shawn Wildermuth

Rate This Article: Add This Article To:

Streaming with Windows Media Services and ASP.NET
( Page 1 of 2 )

Here's something for any software developer to sing about. Shawn Wildermuth shows you how to get started streaming your music or video over the Internet, using Windows Streaming Services and ASP.NET.

I love my music. Like many people these days, I have ripped my entire CD collection to MP3 and I buy all my music online. I am also pretty impatient. I never jumped on the 256MB MP3 player bandwagon because I couldn't figure out what songs I couldn't live without. Now things have changed. I use a 30GB MP3 player but I am running out of room. What's a music addict to do? I realized that since I am pretty connected to the Internet these days, all I should need to do is expose my music collection on an external server and stream them to wherever I am. No need to pick and choose — every album would be at my finger tips.

Luckily, Windows Server 2003 has come to the rescue in the form of Windows Media Services. Included in Windows Server 2003 licensing (Standard and above) is the use of Media Streaming. In this article, I show you how to get started streaming your music or video over the Internet with Windows Streaming Services and ASP.NET.

ADVERTISEMENT

Preparing Your Computer

Using this technology takes a little set-up. Bear with me for a little bit, before we get to code examples.

Before we can get started, we need a Windows Server 2003 computer with IIS and ASP.NET set up. Once the computer's set up with the operating system, we can add Windows Media Services (WMS). To do this, go to Add/Remove Programs in the Control Panel, where you will see the dialog in Figure 1:

Figure 1: Add/Remove Programs

Click on "Add/Remove Windows Components" to show the Windows Components dialog, as seen in Figure 2:

Figure 2: Windows Components

If you scroll to the bottom of the list, you will see Windows Media Services. Click on the check box, and press Next to install Windows Media Services. Now we're ready to add our content.

Exposing Content

Once you have a computer ready for Windows Media Services, you want to expose some content. To do this, launch the Windows Media Services Management Console, as seen in Figure 3:

Figure 3: Windows Media Service Console

Once in the console, we can expose our content. This is done through what Windows Media Services calls a publishing point. Right-click the publishing-points node, and select "Add Publishing Point (Advanced)" to see the dialog shown in Figure 4:

Figure 4: New Publishing Point

In this dialog, you specify the type of stream, the location, and the name. In our case, we want to expose an on-demand publishing point: a directory where our MP3s are stored. Do the following:

  • Click the "On-demand" radio button.
  • Enter a name for the publishing point. This name becomes part of the URL to your content, so short and memorable is important.
  • In the "Location of content" text box, type the directory where the media is stored.
  • Last, pick Directory as the Content Type. (There are a myriad of publishing points, but for the purposes of this article we only discuss the Directory type.)

After doing this, your dialog will look something like Figure 5:

Figure 5: Finished Dialog

Now you have a publishing point. Before you can use it, you have to figure out how to handle authentication. By default, new publishing points have no authentication enabled, which means your content isn't available outside your own computer. Click on the Properties tab of your publishing point, and select "Authentication" from the property list to reveal a screen like the one shown in Figure 6:

Figure 6: Authentication

In my case, I chose just to use Negotiate Authentication (which in turn uses NT authentication), as I am the only one to whom I want to stream my content. Logistically, more than one stream would eat up all my upstream bandwidth, so I decided to rely on NT authentication more for practical reasons than legal ones. Now we are ready to try out our stream.

Testing Our Stream

Now that we have our server set up, we want to test out to see if it can stream content. Windows Media Services supports three out of the box streaming types:

  • RTSP with TCP-based transport (RTSPT)
  • RTSP with UDP-based transport (RTSPU)
  • HTTP transport

By default, RTSP uses port 1755 and the HTTP transport uses port 80. Depending on your network configuration, you either need to open a port in your firewall or change these default ports. In general, I use the HTTP transport since it works at most of my clients with the fewest headaches.

There are two ways to construct an URL to a specific song on your server, using http and using mms. The mms protocol is a Windows Media Player specific protocol that supports fail-over to all three transport types; RTSPT, RTSPU then HTTP. Assuming you can use the standard port (80) for http, using mms URLs is most effective.

Crafting an URL is quite simple: the protocol, the machine name, the publishing point name, and the path to the media. For example, using mms, to a machine name called music.mydomain.com, on the publishing pointed called mymusic for the song in d:\ourmusic\10,000 Maniacs\In My Tribe\What's the Matter Here.mp3 would look like so:

mms://music.mydomain.com/mymusic/10,000 maniacs/in my tribe/what's the matter here.mp3

We don't include the d:\ourmusic as part of the path, since that was what we used for the root to our publishing point. If you put your new URL in Windows Media Player, you should hear the sweet sound of Natalie Merchant (or your favorite artist).

One caveat is that the mms protocol expects port 80 for the failover to the http protocol. To expose your music over another http protocol, you will be forced to use the http protocol instead. The form is identical except for the replacing the mms with http and postpending the port (e.g. 8080):

http://music.mydomain.com:8080/mymusic/10,000 maniacs/in my tribe/what's the matter here.mp3

Pointing to specific files is interesting, but I want to be able to browse my music and put together ad-hoc playlists. Unfortunately, there is nothing built-in with Windows Media Services to allow this. To create our user interface, we can go to ASP.NET.



 
 
>>> More Techniques Articles          >>> More By Shawn Wildermuth
 



Microsoft's Future: A Chat With Their CTO, Barry Briggs

Play Video >

All Videos >

Julia explores the Robotics Studio!

Read now >

Messages to Bill Gates!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.