
Playing WAV from Embedded Resource
Hi,
I am trying to play a wav from an embedded resource. I have added a file
and changed the BuildAction to Embedded Resource. I can not get the stream
to play. It says the stream length is nothing. Can somebody please help.
Below is the code.
Thanks,
Dan
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySound" (ByVal
pszSound() As Byte, ByVal hMod As Int16, ByVal fdwSound As Long) As Boolean
Public RetValue As Boolean
Public Enum zzSound
Async = &H1L
Memory = &H4L
Resource = &H40004L
Sync = &H0L
End Enum
Public Sub PlayAudioFromRes(ByVal filename As String)
Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly
Dim Stream As System.IO.Stream
Dim buffer() As Byte
filename = oAssembly.GetName.Name & "." & filename
Stream = oAssembly.GetManifestResourceStream(filename)
ReDim buffer(CType(Stream.Length, Integer))
Stream.Read(buffer, 0, buffer.Length)
RetValue = PlaySound(buffer, 0, zzSound.Memory + zzSound.Async)
End Sub