C# - Playing wavs

Diablicolic

Well-known member
Joined
Jul 28, 2003
Messages
168
Location
Your Neighbor
Ive searched everywhere and I cant find an example that works! I dont want tutorials, I want an example of playing a wav called: "MySound.wav" that would be in the same folder with the application.

Could someone cook me up a quick example of using a sound in a program for the button1 click event? :-\
 
You can use PlaySound, I dont trust myself to write a C# example at the moment but a VB.Net one is:
Code:
<DLLImport("winmm.dll")>Public Function sndPlaySound(ByVal Path As String, ByVal Flags As Integer) As Integer
End Function
Public Const SND_ASYNC As Integer = &H1
Public Const SND_FILENAME As Integer = &H20000

sndPlaySound("C:\MySound.wav", SND_ASYNC Or SND_FILENAME)
 
But thats the problem, I dont know how to change VB.NET to C# :(

Im at the very beginning stages of C#, so I only know so much. I know how to do sounds in VB.NET, just not in C# because its a little weird and requires skills that I dont know yet.
 
Its not that difficult; just look at the similarities between this
code and the above:

C#:
// All this goes in general declarations:
[DLLImport("winmm.dll")] public int sndPlaySound(string path, int flags) {}

const int SND_ASYNC = 0x1
const int SND_FILENAME = 0x20000

// And to play the sound:
sndPlaySound("C:\MySound.wav", SND_ASYNC | SND_FILENAME);
 
Last edited by a moderator:
You should use [api]PlaySound[/api] - sndPlaySound is deprecated.
 
Back
Top