我正在使用带有Windows Media Service的Windows Server 2008 R2。在客户端,我想使用Silverlight播放媒体文件。我使用的是VSTS 2008 + Silverlight 3 + ASP.Net + .Net 3.5。我想知道Silverlight是否支持从Windows Media Service播放mms流媒体文件?如果是,我可以快速测试任何代码样本吗?
答案 0 :(得分:0)
Silverlight中的MediaElement支持通过mms进行流式传输。您应该查看Silverlight的MSDN audio and video overview。
这是一个非常基本的Silverlight应用程序,它可以控制MediaElement并显示媒体状态/缓冲状态:
<强> 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();
}
}