![]() |
Multimedia »
General Graphics »
General
Intermediate
Playing wav files with .NETBy Edward MoemekaThis article shows simple straightforward way to play wav files in .NET using c# |
C#.NET 1.0, .NET 1.1, WinXPVS.NET2003, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 parameterPlaySound(somefile.wav",0,0);That's it, you're good to go.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 26 Jan 2004 Editor: |
Copyright 2004 by Edward Moemeka Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |