API Declaration
Declare Auto Function sndPlaySound Lib "WINMM.DLL" (ByVal FileName As String, ByVal Options As Int32) As Int32
For Info
API Call Flags for sndPlaySound
Const SND_SYNC As Long = &H0 synchronize playback
Const SND_ASYNC As Long = &H1 played async
Const SND_NODEFAULT As Long = &H2 No default
Const SND_LOOP As Long = &H8 loop the wave
Const SND_NOSTOP As Long = &H10 dont stop current sound if one playing
Const SND_NOWAIT As Long = &H2000 Do not wait if the sound driver is busy.
Const SND_ALIAS As Long = &H10000 Play a Windows sound (such as SystemStart, Asterisk, etc.).
eg of calling it
Public Sub PlayAWave(ByVal Soundfile As String, Optional ByVal MaxLoops As Integer = 1)
Dim i As Integer
For i = 1 To MaxLoops
Play Async - ie. Dont lock up the application
sndPlaySound(Soundfile, SND_ASYNC)
End Sub
Dim FileName As String = "1.wav"
Dim MyStream As Stream
Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly
Dim nSpace As String = oAssembly.GetName.Name.ToString
MyStream = oAssembly.GetManifestResourceStream(nSpace + "." + "wav")
Dim bStr(MyStream.Length) As Byte
MyStream.Read(bStr, 0, Int(MyStream.Length))
PlaySound(MyStream, 0, SND_ASYNC Or SND_MEMORY)
Public Class _Win32
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As Byte(), ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
Public Const SND_ASYNC As Integer = &H1
Public Const SND_MEMORY As Integer = &H4
End Class
/// then in a button click event of your Form ...
Dim strPath As String = Application.ProductName & ".online.wav" /// must be an embedded .Wav files valid path here
Dim sStream As IO.Stream = Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strPath)
Dim strLength As Integer = sStream.Length
Dim sndByte(strLength) As Byte
sStream.Read(sndByte, 0, strLength)
sStream.Close()
_Win32.PlaySound(sndByte, 0, _Win32.SND_ASYNC Or _Win32.SND_MEMORY)
using Microsoft.DirectX.AudioVideoPlayback;
namespace FOoBar
{
class Foo
{
[STAThread]
static void Main(string[] args)
{
//open the wav file and play it
using(Audio wavFile = new Audio(@"C:\myWavFile.wav", true))
{
}
}
}
}
/// System.Windows.Forms.Sound ( visual studio Whidbey )
Dim strPath As String = "WindowsApplication1.online.wav" /// path to a valid embedded .wav file
Dim snd As New Sound(Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strPath))
snd.Play()