首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在特定时间播放声音- Winmm.dll - VB.Net

在特定时间播放声音- Winmm.dll - VB.Net
EN

Stack Overflow用户
提问于 2020-08-25 16:13:15
回答 1查看 428关注 0票数 0

我开始使用winmm.dll播放声音(它提供了一次播放多个声音并设置音频参数的可能性),但是我找不到这个库所有函数的有效列表。

我有一个包含更多音乐的Wav文件,所以我必须单独启动它们。

我有这样的代码:

代码语言:javascript
复制
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中是否有一个函数可以在特定的时间开始播放声音?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-25 16:54:11

最后,我找到了一个解决方案:

要在特定时间播放声音,我必须使用以下代码:

mciSendString(“播放来自13000的MediaSound,Nothing,0,IntPtr.Zero)

在这种情况下,我开始玩13秒

完整法典:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63583000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档