views:

271

answers:

1

Hello everyone,

I am using Windows Server 2008 R2 with Windows Media Service. At the client side, I want to use Silverlight to play the media file. I am using VSTS 2008 + Silverlight 3 + ASP.Net + .Net 3.5. I want to know whether Silverlight supports play mms streaming file from Windows Media Service? If yes, any code samples that I can make a quick test?

thanks in advance, George

A: 

The MediaElement in Silverlight supports streaming via mms. You should have a look at the MSDN audio and video overview for Silverlight.

Here is a very basic Silverlight app which can control a MediaElement and shows the media state / buffering status:

XAML

<UserControl x:Class="StreamingTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <StackPanel Orientation="Vertical">
            <MediaElement x:Name="MediaElement" Width="640" Height="480" Source="mms://danarec:8080"/>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <TextBlock x:Name="Status" Margin="0,5"/>
                <TextBlock x:Name="Buffer" Margin="10,5"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Button x:Name="Play" Content="Play" Click="Play_Click"/>
                <Button x:Name="Pause" Content="Pause" Click="Pause_Click"/>
                <Button x:Name="Stop" Content="Stop" Click="Stop_Click"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>

C#

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();

        this.MediaElement.CurrentStateChanged += (sender, e) =>
        {
            this.Status.Text = this.MediaElement.CurrentState.ToString();
            this.Buffer.Visibility = this.MediaElement.CurrentState == MediaElementState.Buffering ? Visibility.Visible : Visibility.Collapsed;
        };

        this.MediaElement.BufferingProgressChanged += (sender, e) =>
        {
            this.Buffer.Text = string.Format("{0:0.0} %", this.MediaElement.BufferingProgress * 100);
        };
    }

    private void Play_Click(object sender, RoutedEventArgs e)
    {
        this.MediaElement.Play();
    }

    private void Pause_Click(object sender, RoutedEventArgs e)
    {
        this.MediaElement.Pause();
    }

    private void Stop_Click(object sender, RoutedEventArgs e)
    {
        this.MediaElement.Stop();
    }
}
Dan Auclair