How to use MediaElement and play . wmv file (video file) in WPF application?
Are you new to WPF and its various usage? This code will help you to understand why to use MediaElement and how to play videos through WPF application?
WPF applications can be used for playing videos by using MediaElement class. Various video files can be played in different sytem's windows shapes. I have used Ellipse.
To play video file. Video will be shown in Ellipse at runtime.
Create WPF application and add this code in MainWindow.xaml
<Window x:Class="exampleMediaElement.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
Background="Transparent"
AllowsTransparency="True"
MouseLeftButtonDown="Window_MouseLeftButtonDown"
Title="MainWindow"
Height="450" Width="650">
<Grid>
<TextBlock Text="Welcome" FontSize="20"
FontWeight="ExtraBold"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Ellipse>
<Ellipse.Fill>
<VisualBrush>
<VisualBrush.Visual>
<MediaElement Source="videofilepath\filename.wmv"
LoadedBehavior="Play"/>
</VisualBrush.Visual>
</VisualBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
</Window>
Add following code in MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Documents;
namespace exampleMediaElement
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
}
}
Press F5 to execute this application and check whether you can see video file mentioned by you or not.