Requirements:
- Three buttons.
- One media element to run media file.
- Two sliders, one for volume and another for controlling video(forward and Backward) as shown below fig.

1. Design Screen as Shown above, To design copy the code given below to Xaml file
Xaml (Design)
Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="RNTP® Player" Height="497" Width="796" AllowDrop="True" Drop="Window_Drop">
<Viewbox Stretch="Fill">
<Grid>
<MediaElement Height="402" HorizontalAlignment="Left" Name="mediaElement1" VerticalAlignment="Top" Width="774" Cursor="Wait" MediaOpened="mediaElement1_MediaOpened" Stretch="UniformToFill" />
<Button Content="Play" Height="23" HorizontalAlignment="Left" Margin="0,432,0,0" Name="btPlay" VerticalAlignment="Top" Width="75" Cursor="Hand" Click="btPlay_Click" />
<Button Content="Pause" Height="23" HorizontalAlignment="Left" Margin="81,432,0,0" Name="btPause" VerticalAlignment="Top" Width="75" Cursor="Hand" Click=" btPause_Click" />
<Button Content="Stop" Height="23" HorizontalAlignment="Left" Margin="162,432,0,0" Name="btStop" VerticalAlignment="Top" Width="75" Cursor="Hand" Click=" btStop_Click" />
<Slider Height="23" HorizontalAlignment="Left" Margin="0,406,0,0" Name="slider_seek" VerticalAlignment="Top" Width="774" Cursor="Pen" ValueChanged="slider_seek_ValueChanged" />
<Slider Height="23" HorizontalAlignment="Left" Margin="621,429,0,0" Name="slider_vol" VerticalAlignment="Top" Width="126" Cursor="Pen" Maximum="1" LargeChange="0.1" SmallChange="0.01" Value="1" ValueChanged="slider_vol_ValueChanged" />
<Label Content="Volume" Foreground="blue" Margin="621,409,0,26" /> </Grid>
</Viewbox>
</Window>
2. Now write C# code as given below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace RNTPvideo_player
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow: Window
{
DispatcherTimer timer;
public MainWindow()
{
InitializeComponent();
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
slider_seek.Value = mediaElement1.Position.TotalSeconds;
}
private void btPlay_Click(object sender, RoutedEventArgs e)
{
if (mediaElement1.Source != null)
{
mediaElement1.Play();
}
else
{
MessageBox.Show("Please drag and drop video to play");
}
}
private void btPause_Click(object sender, RoutedEventArgs e)
{
if (mediaElement1.Source != null)
{
mediaElement1.Pause();
}
else
{
MessageBox.Show("There is no video to play");
}
}
private void btStop_Click(object sender, RoutedEventArgs e)
{
if (mediaElement1.Source != null)
{
mediaElement1.Stop();
}
else
{
MessageBox.Show("There is no video to stop");
}
}
private void slider_vol_ValueChanged(object sender, RoutedPropertyChangedEventArgs < double > e)
{
mediaElement1.Volume = (double) slider_vol.Value;
}
private void slider_seek_ValueChanged(object sender, RoutedPropertyChangedEventArgs < double > e)
{
mediaElement1.Position = TimeSpan.FromSeconds(slider_seek.Value);
}
private void Window_Drop(object sender, DragEventArgs e)
{
string filename = (string)((DataObject) e.Data).GetFileDropList()[0];
mediaElement1.Source = new Uri(filename);
mediaElement1.LoadedBehavior = MediaState.Manual;
mediaElement1.UnloadedBehavior = MediaState.Manual;
mediaElement1.Volume = (double) slider_vol.Value;
mediaElement1.Play();
}
private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
{
TimeSpan ts = mediaElement1.NaturalDuration.TimeSpan;
slider_seek.Maximum = ts.TotalSeconds;
timer.Start();
}
}
}
