
Introduction
This is a simple class that shows how to play Wave files in a .NET project, using Windows API. Here, you will find the way to play embedded resources, external files, or Windows system Waves.
Using the code
Using the code is very simple, you have to choose if you want to play a file: Sound.PlayWaveFile("Filename.wav")
, an embedded resource: Sound.PlayWaveResource("Embedded.wav")
, or a system sound: Sound.PlayWaveSystem("SystemExit")
.
...
Public Class Sound
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
As Byte(), ByVal hmod As Integer, ByVal flags As Integer) As Integer
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_MEMORY = &H4
Public Const SND_ALIAS = &H10000
Public Const SND_NODEFAULT = &H2
Public Const SND_FILENAME = &H20000
Public Const SND_RESOURCE = &H40004
...
End Class
Private Sub btnFile_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnFile.Click
Sound.PlayWaveFile("sn01088a.wav")
End Sub
Private Sub btnEmbed_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnEmbed.Click
Sound.PlayWaveResource("The Microsoft Sound.wav")
End Sub
Private Sub btnSystem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSystem.Click
Sound.PlayWaveSystem("SystemExit")
End Sub
All the job is done by the PlaySound
function.
Points of Interest
This is an "all in one" Sound
class for your .NET applications (File, Resource, System sounds).
History
First release.