Play a wav file by using SoundPlayer : SoundPlayer : Development C# Examples


C# Examples » Development » SoundPlayer »

 

Play a wav file by using SoundPlayer









    
using  System;
using  System.Windows.Forms;
using  System.Media;

public  class  MainClass
{
        public  static  void  Main()  {
                OpenFileDialog  openDialog  =  new  OpenFileDialog();
                openDialog.Filter  =  "WAV  Files|*.wav|All  Files|*.*";

                if  (DialogResult.OK  ==  openDialog.ShowDialog())
                {
                        SoundPlayer  player  =  new  SoundPlayer(openDialog.FileName);

                        try
                        {
                                player.Play();
                        }
                        catch  (Exception)
                        {
                                MessageBox.Show("An  error  occurred  while  playing  media.");
                        }
                        finally
                        {
                                player.Dispose();
                        }
                }
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» SoundPlayer