
Projects By LANGUAGE
Libraries
Articles & seminars
Source Code

Silverlight includes support to play audio and video files.
|
|||
Adding media to a page is as simple as adding a MediaElement to your markup and providing a Uniform Resource Identifier (URI) to the media to play. The following example creates a MediaElement and sets its Source property to the URI of a video file. The MediaElement begins playing when the page loads. |
|||
XAML |
|||
MediaElement Object | |||
|
| |||
|
<StackPanel Width="300" Height="300"> <MediaElement x:Name="media" Source="xbox.wmv"Width="300" Height="300" /> </StackPanel> |
|||
|
|||
|
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <MediaElement x:Name="media" Source="xbox.wmv" Width="300" Height="300" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" /> <!-- Stops media playback.--> <Button Click="StopMedia" Grid.Column="0" Grid.Row="1" Content="Stop" /> <!-- Pauses media playback. --> <Button Click="PauseMedia" Grid.Column="1" Grid.Row="1" Content="Pause" /> <!-- Begins media playback. --> <Button Click="PlayMedia" Grid.Column="2" Grid.Row="1" Content="Play" /> </Grid> |
|||
| C# | |||
|
private void StopMedia(object sender, RoutedEventArgs e) { media.Stop(); } private void PauseMedia(object sender, RoutedEventArgs e) { media.Pause(); } private void PlayMedia(object sender, RoutedEventArgs e) { media.Play(); } |
|||
|
| |||
| Visual Basic | |||
|
Private Sub StopMedia(ByVal sender As Object, ByVal e As RoutedEventArgs) media.Stop() End Sub Private Sub PauseMedia(ByVal sender As Object, ByVal e As RoutedEventArgs) media.Pause() End Sub Private Sub PlayMedia(ByVal sender As Object, ByVal e As RoutedEventArgs) media.Play() End Sub |
|||
| Download code | |||
