' Declarations...
' Play Sound flags
Private Const SND_ASYNC As Integer = &H1
Private Const SND_LOOP As Integer = &H8
Private Const SND_MEMORY As Integer = &H4
Private Const SND_NODEFAULT As Integer = &H2
Private Const SND_NOSTOP As Integer = &H10
Private Const SND_SYNC As Integer = &H0
' Play Sound declaration
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As Byte(), ByVal uFlags As Integer) As Integer
' Calling Code...
' Name of the resource to extract
Dim rName As String = "cameraclick.wav"
' Obtain the assembly name and replace '-' with an underscore
Dim rSchema As String = Replace(Reflection.Assembly.GetExecutingAssembly.GetName.Name, "-", "_") & "." & rName
' Retreive the resource as a stream
Dim rStream As IO.Stream = Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(rSchema)
' Read the stream into a byte buffer
Dim buffer(rStream.Length) As Byte
rStream.Read(buffer, 0, buffer.Length - 1)
' Play the sound
sndPlaySound(buffer, SND_MEMORY Or SND_ASYNC)

博客展示了一段代码,定义了播放声音的标志常量,声明了播放声音的函数。通过获取程序集名称、资源流,将流读取到字节缓冲区,最终使用缓冲区和标志常量调用函数实现异步播放声音。
112

被折叠的 条评论
为什么被折叠?



