One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man

Wednesday, January 26, 2011

How to create a simple media player using Visual Studio C#

As usually you have to create a windows form application in visual studio
File->New->Project


Then you have to select c# windows form application and give the name and location for your project. After that press ok.


Then Right-click on the toolbox and press "choose Items". Then the following window will appear.


Press "COM component" tab.
Then put a tick on windows media player according to the following picture and press OK.


Now you can see there is tool "Windows media player" on the bottom of the toolbox.


Then drag and drop and change the size as you wish.


After that drag and drop a Menu Strip from the toolbox and give the first one as "Open".


Then Double-click on "Open".



Write a coding as it is in the following picture.



                    OpenFileDialog open = new OpenFileDialog();
                    open.Title = "Open";
                    open.Filter = "All Files|*.*";
                    try
                    {
            
                              if(open.ShowDialog()==System.Windows.Forms.DialogResult.OK)
                                                      axWindowsMediaPlayer1.URL=(open.FileName);
                    }
                    catch (Exception ex)
                    {
                             MessageBox.Show(ex.Message.ToString(),"Error", MessageBoxButtons.OK,       MessageBoxIcon.Error);                
                    }

At last run the program and watch a movie using your own media player.

1 comment:

  1. I tried it and it worked macho. Can we use the player by taking only the generated exe file ? I tried it but it didn't work.

    ReplyDelete