vb.net:单击按钮时播放音频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35546492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vb.net: play audio when button is clicked
提问by Gideon Pradas Padua
is there a way to play a audio/music every time the button is click?I use this code to play audio mciSendString("play " & musicAlias, CStr(0), 0, 0).I want to play it every time the button is click. I already put it in the button but the problem is its only play ones.
有没有办法在每次单击按钮时播放音频/音乐?我使用此代码播放音频mciSendString("play " & musicAlias, CStr(0), 0, 0)。我想在每次单击按钮时播放。我已经把它放在按钮上,但问题是它唯一的播放按钮。
thanks in advance.
提前致谢。
回答by GrindelOh
10s of googling gives you several answers..
10 多岁的谷歌搜索给了你几个答案..
For wave-files(.wav) you can simply use My.Computer.Audio.Play("C:\Users\Public\Music\Sample Music\Kalimba.wav.")
对于波形文件(.wav),您可以简单地使用 My.Computer.Audio.Play("C:\Users\Public\Music\Sample Music\Kalimba.wav.")
MP3-files are a bit more complicated, even more if you dont want to use the WMP controll element.
MP3 文件有点复杂,如果您不想使用 WMP 控件元素,则更复杂。
Hereyou have another post with the same requests as you have. And there are several SO posts with the same topic.
在这里,您有另一篇与您提出相同要求的帖子。并且有几个具有相同主题的 SO 帖子。
回答by Gideon Pradas Padua
i got it sir and its work like what i want.
我明白了,先生,它的工作就像我想要的那样。
Private Sub playSound()
Dim Mytone As New System.Media.SoundPlayer
Mytone.SoundLocation = "audio.wav"
Mytone.Load()
Mytone.Play()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cexitButton.Click
playsound()
End Sub

