vb.net - 在特定时间播放声音 - Winmm.dll - VB.Net
问题描述
我开始使用 winmm.dll 播放声音(它提供了一次播放多个声音并设置音频参数的可能性),但我找不到该库所有功能的有效列表。
我有一个包含更多音乐的 Wav 文件,所以我必须单独启动它们。
我有这个代码:
Imports System.Text
Imports System.Runtime.InteropServices
Public class SoundPlayer
<DllImport("winmm.dll")> Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
Public sub PlayMusicWithTime(SelectedTime as String)
mciSendString("open " & Chr(34) & Application.StartupPath & "\Resources\Sounds\" & soundFileName & Chr(34) & " type waveaudio alias MediaSound", Nothing, 0, IntPtr.Zero)
mciSendString("setaudio MediaSound volume to 1000", Nothing, 0, IntPtr.Zero)
' There should be a function here that make the sound start at the input value
mciSendString("play MediaSound", Nothing, 0, IntPtr.Zero)
End Sub
End Class
那么 Winmm.dll 中是否有一个函数可以在特定时间开始播放声音?
解决方案
最后我找到了一个解决方案:
要在特定时间播放声音,我必须使用以下代码:
mciSendString("从 13000 播放 MediaSound, Nothing, 0, IntPtr.Zero)
在这种情况下,我从 13 秒开始玩
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ _ _ - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ _ _ - - - - - - - - - - -- - -
完整代码:
Imports System.Text
Imports System.Runtime.InteropServices
Public class SoundPlayer
<DllImport("winmm.dll")> Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
Public sub PlayMusicWithTime(SelectedTime as Integer)
mciSendString("open Sound1.wav type waveaudio alias MediaSound", Nothing, 0, IntPtr.Zero)
mciSendString("setaudio MediaSound volume to 1000", Nothing, 0, IntPtr.Zero)
mciSendString("play MediaSound from " & SelectedTime.toString, Nothing, 0, IntPtr.Zero)
End Sub
End Class
推荐阅读
- http - 如何像在 curl 中一样在 clojure http 请求中设置“无代理”?
- excel - 计算具有多个条件的行
- java - log4j 根据应用程序的登录用户在不同文件中添加日志
- javascript - 如何将从输入字段中获取的画布名称与 Javascript 中的画布合并?
- c++ - 如何修复:在 c++ 中使用 pthread 执行 lambda 表达式
- c# - 更新到 .net core 2.2 后信号 r 不工作
- php - 如何在 woocommerce 我的帐户页面中重新排序自定义选项卡?
- java - AES 256 java 和 .Net 兼容的加密和解密?
- python - 如何从数据框中制作数据透视表?
- java - 重构空的 if 语句