SIGN UP MEMBER LOGIN:    
ARTICLE

Playing Audio and Video Files Using C#

Posted by Prashanth Chindam Articles | Windows Forms C# November 03, 2010
This article shows to develop a windows application for playing audio and video files using c#.net.
Reader Level:
Download Files:
 

Objective:

To develop a windows application for playing audio and video files using c#.net.

Design:

1.gif

Design the form as above with an OpenFileDialog contol, one Button and 'Windows Media Player' contol (COM component).

Note that OpenFileDialog control appears below the form(not on the form), which is used in our application for browsing audio/video files.

Steps for adding 'Windows Media Player' control (COM component) into Toolbox:

By default, 'Windows Media Player' control is not provided in the toolbox, we have to add it into the toolbox if required.

Inorder to add 'Windows Media Player' control into toolbox

Right click on 'General' tab (or anyother tab) in toolbox ->select 'Choose Items...' ->select 'COM Components' tab ->select 'Windows Media Player' ->click on 'OK' button.

2.gif

3.gif
 
'Windows Media Player' control will appear in the toolbox.

4.gif

Now, drag 'Windows Media Player' control on to the form and place a button on it with text as 'Browse..' as shown in the design.

Code:

using System;
using System.Windows.Forms;

namespace mymediaplayer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "(mp3,wav,mp4,mov,wmv,mpg)|*.mp3;*.wav;*.mp4;*.mov;*.wmv;*.mpg|all files|*.*";
            if(openFileDialog1.ShowDialog()==DialogResult.OK)
                axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
        }
    }
}

Output:

5.gif 

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

this code suits only for files with .wmv,.avi extensions.i cant play the files with .mp3,.mp4 extensions.give some information about that.. thanks in advance

Posted by lokesh j Mar 27, 2012

Hi Prashanth Chindam, Thanks for this post, please specify that it will work on web application or not, Thanks.............

Posted by A K Das Mar 26, 2012

hello want to know how can I play a video from a streamreader, and he's normal http bloquiado with basic authentication. part of the code: "String result; HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://urldosite/meuvideo.mp4"); request.Credentials = new NetworkCredential ("User", "senha000"); request.PreAuthenticate = true; / / Get response HttpWebResponse response = (HttpWebResponse) request.GetResponse (); StreamReader sr = new StreamReader (response.GetResponseStream ()); result = sr.ReadToEnd (); sr.Close (); " I want to know how to put windows media player to view the video which will result in the variable? example: axwindowsmediaplayer = result;

Posted by igor splynde Mar 05, 2012

hi Prashanth Chindam, this is a nice article. thank you.

Posted by Ken H Feb 28, 2012

How store and retrive video files in Asp.net using C#

Posted by John felix Nov 24, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • 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.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor