MekasDotNet
Skip Navigation Links
Home
---------------
Code Converter
---------------
Downloads
---------------
Forums
---------------
ReferenceSites
-------------
Contact Us

WPF Video Example:

1.This example explains how to use "play", "pause", "mute" and "stop" functions,while working with a video file.
2.Go to -->File-->New Project-->Select WPFApplication-->and name it as WpfVideoApplication.
3.When this project is loaded, it shows the default Design and xaml code windows. The following xml code is written in the xaml window.

4.In the code, we first insert a Grid layout container in the default window. Then we add a stack panel to hold the video element.
5.The video element is inserted using the mediaelement tag. The name is chosen as myvideo, Source is set to the path where the video element resides, loadedBehaviour is set to manual which enables us to control the video file(play, pause etc) manually.
6.Next we define four buttons that display PLAY,PAUSE, STOP AND MUTE respectively. The click attribute of each button is set to the name of the function it calls(playBtn_Click etc).The functions are defined in the code behind(window1.xaml.cs)file.
7.In the code behind file we first set the volume to our video file and play the video by default, when the application is run.(This is shown in lines 25 and 26).
8.Under the PlayBtn_Click function(line 28 and 29), the video file is playing using the code myvideo.play().Similarly pause and stop functionalities are implemented using myvideo.pause() and myvideo.stop() respectively.
9.In the Mute_Click method, if either mute or unmute the file depending upon myvideo.volume. If it is unmuted, we set the volume to zero, and change the text on button to Listen. If its muted, we set the volume back to 100, and change the text on the button to Mute.
10. Finally when we run the application the following output window is seen:

   
Your Feedback:
Post Name:
Post E-mail:  
Post Comment: