5,693,062 members and growing! (18,468 online)
Email Password   helpLost your password?
Multimedia » General Graphics » General     Intermediate

Playing wav files with .NET

By Edward Moemeka

This article shows simple straightforward way to play wav files in .NET using c#
C#Windows, .NET, .NET 1.0, .NET 1.1, WinXPVS.NET2003, Visual Studio, Dev

Posted: 26 Jan 2004
Updated: 26 Jan 2004
Views: 23,600
Bookmarked: 9 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 2.27 Rating: 1.81 out of 5
12 votes, 66.7%
1
1 vote, 5.6%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
5 votes, 27.8%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This article illustrates how simple it is to add sound functionality to any .NET application.  I use the PlaySound win32 function located in the winmm.dll library.  The sample does not include all the different flags associated with fdwSound, these can be acquired in a number of different ways.  try opening a Managed C++ project and typing the PlaySound function in there.  It should give you the signature.  For any of the fdwSound constants you can type them in and either hover the mouse over to get the value, or right click and select go to definition to see where they are defined. 

Here is the basic code for it:

//first I define the function
[DllImport("winmm.dll")]
static extern bool PlaySound(string file, int module, int flags );

//then in the click event of the form i specify this
OpenFileDialog media = new OpenFileDialog();
media.RestoreDirectory = true;
if(media.ShowDialog() == DialogResult.OK){
     string waveFile = media.FileName;
     string extension = System.IO.Path.GetExtension(waveFile);
     if(extension.ToLower() == ".wav"){
          PlaySound(waveFile,0,0x0008); //yep it's really this simple.
    }
}
//You could just use the function with zeros for every other parameter
PlaySound(somefile.wav",0,0);
That's it, you're good to go.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Edward Moemeka


Hi I'm Edward Moemeka,
For more interesting articles about stuff check out my blog at http://moemeka.blogspot.com
To find out about how (mind)! pronounced Mind factorial can help you check out my company site http://www.mindfactorial.com

You can find some of the project I am coordinating at
Location: United States United States

Other popular General Graphics articles:

  • A flexible charting library for .NET
    Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
  • CxImage
    CxImage is a C++ class to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.
  • 3D Pie Chart
    A class library for drawing 3D pie charts.
  • Really cool visual FX
    A set of classes for doing stunning visual effects, including water, plasma and fire.
  • ImageStone
    An article on a library for image manipulation.
Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 26 Jan 2004
Editor:
Copyright 2004 by Edward Moemeka
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project