SIGN UP MEMBER LOGIN:    
ARTICLE

Media Element in WPF

Posted by Diptimaya Patra Articles | WPF with C# February 22, 2010
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.
Reader Level:
Download Files:
 

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.

Crating WPF Application Project

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

MediaElement1.gif

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.

MediaElement2.gif

XAML Reference

MediaElement3.gif

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

MediaElement4.gif

Now we will achieve the functionalities one by one.

Open Media

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

MediaElement5.gif

Add the below code in the respective Button Click event.

MediaElement6.gif

Play and Pause Function

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

MediaElement7.gif

Stop Function

Add the below code in Stop Button Click event.

MediaElement8.gif

Move Back and Forward Function

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

MediaElement9.gif

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.

MediaElement10.gif

MediaElement11.gif

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

Login to add your contents and source code to this article
share this article :
post comment
 

this my first to attempt to work in WPF application please can i ask you .. what is dialogfiles and Dialog result..........thx.

Posted by samar samy Feb 07, 2011

thnx for the tutorial.. but i am not able to play avi files in the media element .. when i select one it shows nothing.. although all the buttons get enabled.. any suggestions from your side..

Posted by Aly Irshad Jan 09, 2011



so, Develop this in silverlight and use it in your application means in your website

Posted by Jitendra Sampathirao Oct 07, 2010

My goal is to play files on my blog or website
I use window player 12

Posted by Gabriel Issah Oct 05, 2010


Hi,
Whats the version  of media player you used?

Posted by Jitendra Sampathirao Oct 05, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor