Customers that I demonstrate Silverlight to, often ask me about Live Streaming using Silverlight. It is actually pretty trivial to demo a live stream.

To create the live source, all you need is a digital video camera that plugs into either a USB port or the 1394 port on your laptop. Your standard DV Handycam is fine(I have tried my Sony Mini DV successfully) , and so are any of the typical clip-on style video conferencing cameras (like a Microsoft Lifecam). Obviously this provides an SD source – to get HD you will probably have to shell out some more money and get one of the new fangled HD consumer cameras.

You will also need an encoder (either Expression Media Encoder or Windows Media Encoder works fine) and a MediaElement on a page pointing to the URL where the encoder publishes the stream. If you want to get fancy and demonstrate a somewhat more realistic scenario, you can also add Windows Media Services as the streaming service to this mix – I typically use Windows Media Services 2008 running in a VM.

Once you plug in the camera and switch to Live Streaming mode in your encoder, xMedia Encoder or WM Encoder will pick up the camera as both a video and an audio source. Below is a snapshot of xMedia Encoder using my Lifecam as a source.

image

The default publishing options for xMedia Encoder is to broadcast over port 8080 - make sure you check the Streaming checkbox in the Output tab.

image

Your MediaElement declaration can look like so:

<MediaElement x:Name="MediaElem" Source="mms://localhost:8080/" AutoPlay="true" Width="800" Height="600" Stretch="Fill"/>

And below is the result - my handsome mug in all its glory :-).

image

If you want to make the scenario a little bit more realistic, you may want to add a streaming service to the mix. It is highly unlikely that a production environment would allow players to directly connect to an encoder.

I have been pretty successfully using  Windows Media Services 2008 on a Windows Server 2008 Enterprise RC0 VM. Once you install Media Services, you will need to add the Streaming Media Server role to the server instance. You will then need to take the following steps to set up Windows Media Server to stream your live content:

  • Enable the HTTP Control Protocol on the Media Server. To do that open up the MMC snap-in for the Media Server, navigate to the root node (should be the name of your server), and the Properties tab within. Select the Control Protocol category, select the "WMS HTTP Server Control Protocol" plug-in, and right click "Properties".  If you are also running IIS on the same box, make sure to select some other port (other than 80) in the property page.

image

  • Bring up the "Add Publishing Point (Advanced)" wizard (right click on the Publishing Points node), and create a Broadcast pub point, and specify "push:*" as the content location. This allows the encoder to push content to the pub point, and activates the pub point automatically once the encoder starts pushing.

image

Once you are done, revisit Expression Media Encoder, and change the Streaming settings in the Output tab to publish to the publishing point you just set up, by providing the URL to the publishing point. The URL is of the format http://[Media Server Name]:[Port You Selected]/[Publishing Point Name]. Clicking the Pre Connect button will confirm connection, and may ask for credentials depending on your domain settings. With this out of the way, if you start Encoding, the stream will automatically be pushed to the Publishing Point by Expression Media Encoder.

image

Your MediaElement declaration can look like so:

<MediaElement x:Name="MediaElem" Source="mms://svr08-mediasvr:49000/SLLiveStream" AutoPlay="true" Width="320" Height="240" Stretch="Fill"/>

And that's all you need to do to get Windows Media Server into the streaming process.