Welcome to EMC Consulting Blogs Sign in | Join | Help

Merrick Chaffer's Blog

Media Streaming in Windows 7 and WPF (Part 2)

In Part 1 I discussed how you can stream windows media from windows 7 machine using windows media player 12 to another. Here I'll show you how you can open an rtsp stream in a WPF windows application using the VLC media player WPF control (http://vlcdotnet.codeplex.com/).

N.B. Up until the time of writing this post, the <MediaElement> that comes with WPF out of the box does not seem to support the rtsp protocol.

This post comes in two parts itself. The first shows how to consume an RTSP stream in WPF using the VLC media player controls, and the second shows how you can create an HTTP stream using vlc media player.

Consuming RTSP media streams in WPF using VLC Media player controls

1. Download the control libraries from the vlc codeplex site. (current version can be found here... http://vlcdotnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31255)

2. Download and install the vlc media player to your hard disk, http://www.videolan.org/vlc/download-windows.html, and make a note of the installation directory containing vlc.exe after the install is complete (as you will need this later).

3. Create  a new WPF windows application project in Visual studio 2008.

4. Add a new Window to your project and make it the start-up window in App.xaml. Then change the XAML mark-up to the following...

<Window x:Class="WindowsApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Wpf="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
        xmlns:Core="clr-namespace:Vlc.DotNet.Core;assembly=Vlc.DotNet.Core"
        xmlns:Medias="clr-namespace:Vlc.DotNet.Core.Medias;assembly=Vlc.DotNet.Core"
        xmlns:Options="clr-namespace:Vlc.DotNet.Core.Options;assembly=Vlc.DotNet.Core"
        Title="Window1"
        Height="640"
        Width="480">
    <Grid>
        <StackPanel Margin="100">
            <Wpf:VlcControl>
                <Wpf:VlcControl.Manager>
                    <Core:VlcManager AutoStart="True"
                                     VlcLibPath="C:\Program Files (x86)\VideoLAN\VLC\"
                                     FullScreen="False">
                        <Core:VlcManager.MediaLibrary>
                            <Core:VlcMediaLibraryManager Loop="False"
                                                         Random="False">
                                <Medias:CustomMedia Mrl="rtsp://SourceIpAddressHere" />
                            </Core:VlcMediaLibraryManager>
                        </Core:VlcManager.MediaLibrary>
                    </Core:VlcManager>
                </Wpf:VlcControl.Manager>
            </Wpf:VlcControl>
        </StackPanel>
    </Grid>
</Window>

5. Be sure to set the VlcLibPath property to the correct path for your installation of the VLC media player. This should match the path where the vlc.exe program has been installed.

6. Change the customer media mrl to match the rtsp stream that you wish to view. If you don't have an RTSP stream to view, then see below for how to create one...

Create an RTSP stream using vlc media player

This second chapter, explains how to create an HTTP stream of an existing avi video on your hard disk, using vlc media player. You can do this on most machines, and therefore do not need to have windows 7 or media player 12 to stream video content on your network, which is quite nice for those of us still on the Windows XP operating system.

1. Assuming you've followed the above steps, then you'll already have vlc media player installed. If not then download it and install from here... http://www.videolan.org/vlc/download-windows.html

2. Open vlc media player, and from the Media menu select the streaming option... (Ctrl+S shortcut)

image

3. From the resulting dialog, select the video file you wish to stream, and then click the stream button...

image

4. Click the Next button on the following screen...

image

5. From the Destinations dialog, check the Display locally option, uncheck the activate transcoding check box, and select HTTP from the New destination drop down, then click Add.

image

6. Type the address of your computer, or computer name, and select the port you wish to stream on (default is 8080), then click the next button.

Note you will have to ensure that your firewall is set up to allow Vlc.exe through (this normally happens as part of the vlc installation though).

image

7. Finally click the stream button, and you're done.

Testing the stream is working.

To test the stream is actually working you can fire up another instance of vlc media player, and simply either hit (Ctrl+V) to paste the address of the stream in and hit enter, or select the Open Network Stream... option (Ctrl+N shortcut), from the Media menu which will guide you through opening the stream.

image

image

You can then test your WPF application (created in the steps above), by setting the MRL attribute in the XAML to http://127.0.0.1:8080 (assuming that's the address of the stream you set up).

Published 01 February 2010 12:04 by merrick.chaffer
Anonymous comments are disabled

This Blog

Syndication

News

Powered by Community Server (Personal Edition), by Telligent Systems