如何解决在特定时间播放声音-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,IntPtr.Zero)
mciSendString("setaudio MediaSound volume to 1000",IntPtr.Zero)
' There should be a function here that make the sound start at the input value
mciSendString("play MediaSound",IntPtr.Zero)
End Sub
End Class
Winmm.dll中是否有一个函数可以在特定时间开始播放声音?
解决方法
最后我找到了解决方法:
要在特定时间播放声音,我必须使用以下代码:
mciSendString(“播放MediaSound from 13000,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,IntPtr.Zero)
mciSendString("setaudio MediaSound volume to 1000",IntPtr.Zero)
mciSendString("play MediaSound from " & SelectedTime.toString,IntPtr.Zero)
End Sub
End Class
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。