WELCOME TO SILVERLIGHT

DARE TO BE DIFFERENT

Wednesday, June 10, 2009

Using MediaElement Control in Silverlight

  • MediaElement Control enables the user to professionally present the application in Silverlight.
  • MediaElement is same as the image brush,in MediaElement we can add Video and Audio in our applications.

Let us see a simple example

Here we use three Button Control namely Play,Pause andStop.

Play: Plays the Video.

Pause:Pauses the Video.

Stop: Stops the Video.

XAML Coding:

<MediaElement Name="abc" Source="mov1.wmv" ></MediaElement>
<Button Name="a1" Height="40" Width="40" VerticalAlignment="Bottom" HorizontalAlignment="Left" Content="play" Click="Button_Click"></Button>
<Button Name="a2" Height="40" Width="40" VerticalAlignment="Bottom" HorizontalAlignment="Center" Content="pause" Click="Button_Click_1"></Button>
<Button Name="a3" Height="40" Width="40" VerticalAlignment="Bottom" HorizontalAlignment="Right" Content="stop" Click="Button_Click_2"></Button>


C# Coding:

public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
abc.Play();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
abc.Pause();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
abc.Stop();
}
}

Output:




1 comment: