[Solved].wav resource
1.) I added a 'bleep22.wav' to my resources.
How can I play the file from my resources on button event?
How can I play the file from my resources on button event?
Dim ES As New System.Media.SoundPlayer() ES.SoundLocation = "Wav File" ES.Load() ES.Play()
My.Computer.Audio.Play(My.Resources."ResourceFile.wav", AudioPlayMode.BackgroundLoop)
Imports System.Runtime.InteropServices Imports System.Resources Imports System.IO Imports System
Public Class Form1
Public Class Winmm
Public Const SND_ASYNC As UInt32 = 1
Public Const SND_MEMORY As UInt32 = 4
<DllImport("Winmm.dll")> _
Public Shared Function PlaySound(ByVal data As Byte(), ByVal hMod As IntPtr, ByVal dwFlags As UInt32) As Boolean
End Function
Public Shared Sub PlayWavResource(ByVal wav As String)
Dim strNameSpace As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString()
Dim str As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream((strNameSpace & ".") + wav)
If str Is Nothing Then
Exit Sub
End If
Dim bStr As Byte() = New [Byte](str.Length - 1) {}
str.Read(bStr, 0, CInt(str.Length))
PlaySound(bStr, IntPtr.Zero, SND_ASYNC Or SND_MEMORY)
End Sub
Win32.Winmm.PlayWavResource("YourwaveFile.wav")
, More professional
My.Computer.Audio.Play(My.Resources."ResourceFile.wav", AudioPlayMode.WaitToComplete)

