Media Element In WPF

No.of Views2219
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  11 May 2010 09:05:17
Tag : WPF , Miscellaneous Controls
In this article we will see how to use Media Element in WPF and we will explore some of the basic functionalities such as Play, Pause, Stop, Back and Forward.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article we will see how to use Media Element in WPF and we will explore some of the basic functionalities such as Play, Pause, Stop, Back and Forward.

Creating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as MediaSampleWPF.

 

Image Loading

Now we will first design the application so that all the functionalities would be clear to us.Add a Media Element, and several Buttons for the functions to be achieved.The following figure is the simple design of the application.
 

Image Loading

XAML Reference

Image Loading

Now to start with in the beginning of the application all the Buttons except Open should not be enabled. So lets do that.

Image Loading

Now we will achieve the functionalities one by one.

Open Media

Add reference to the System.Windows.Forms DLL to use the OpenFileDialog.

 

Image Loading

Add the below code in the respective Button Click event.

 

Image Loading

Play and Pause Function

Add the below code in Play Button Click event to achieve the Play and Pause functions.

 

Image Loading

Stop Function

Add the below code in Stop Button Click event.

 

Image Loading

Move Back and Forward Function

Add the below code in respective Back and Forward Button Click events to achieve Back and Forward.

 

Image Loading

That’s it run the application. As we mentioned in the code for opening only WMV files, you can open only WMV file. You can add other extensions like AVI, MPG and MPEG to the Open function.

 

Image Loading
Image Loading

Hope you guys like this article. It’s for the beginner level

Sample Project Source

Download source files -47 kb

 
Sign Up to vote for this article
 
About Author
 
dpatra
Occupation-Not Provided
Company-Not Provided
Member Type-Expert
Location-Not Provided
Joined date-13 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
By:Kunwar DeepDate Of Posted:3/13/2012 5:58:49 AM
WPF Media Element
This is one of the best answer so far, I have read online. Just useful information. Very well presented. Some other articles too helped me lot in completing my task which I was found during searching this article over the internet, URL of that posts are... http://www.c-sharpcorner.com/uploadfile/dpatra/media-element-in-wpf/ http://mindstick.com/Articles/3dab95c8-380f-4715-b13e-e4cb3b5a64b4/?Media%20Element%20in%20WPF
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top