vb.net中如何播放声音,是要什么控件嘛?My.Computer.Audio.Play("SoundFile.wav")
SoundFile.wav是vb.net调用beep你要播放vb.net调用beep的声音文件vb.net调用beep的路径
VB.net如何加载音效?方法一:调用系统DLL(这个有点不完善,也就是播放声音时窗体无法控制,效果相当于Enabled=true,但音频播放完毕后就没事了)
Private Declare Function sndPlaySound Lib "Winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SoundFile As String, Result As Long
SoundFile = "D:\KuGou\Pianoboy - 第105天.wav" '此处为路径
Result = sndPlaySound(SoundFile, 0)
End Sub
方法二:使用WindowsMediaPlayer(WindowsMediaPlayer1的可见为False)
先添加一个windowsmediaplayer控件(工具箱里没有,需要手动添加)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WindowsMediaPlayer1.visible=False
Me.WindowsMediaPlayer1.URL = "D:\KuGou\Pianoboy - 第105天.mp3"
End Sub
上面的都是点击button1(按钮1)后播放声音,若是鼠标移动到某控件上发出声音的话改一下触发事件就OK了 。
VB.NET中播放背景音乐最简单的办法是什么啊?给你我的程序,自己研究一下吧,我也不是很明白 。
Public Class Form1
Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
Const SND_filename As Integer = H20000
Const SND_alias As Integer = H10000
Const SND_sync As Integer = H0
Declare Auto Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Integer
Declare Auto Function sndPlaySound Lib "winmm.dll" (ByVal filename As String, ByVal options As Integer) As Integer
Private Const SND_memory As Integer = H4
Private Const SND_async As Integer = H1
Private Const proess_domain As String = ""
Const SND_sync1 = H0
Const SND_async1 = H1
Const SND_nodefault = H2
Const SND_loop = H8
Const SND_nostop = H10
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Beep()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFileName As String = "start.wav"
PlaySound(strFileName, 0, SND_filename)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PlaySound("systemstart", 0, SND_alias Or SND_sync)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim ret As Long
Dim strfilename As String
strfilename = "start.wav"
ret = sndPlaySound(strfilename.ToCharArray, 0)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim i As Integer
i = waveOutGetNumDevs()
If i0 Then
MsgBox("可以播放声音", 64, "检测")
Else
MsgBox("不能播放声音", 64, "检测")
End If
End Sub
End Class
我在VB.net程序中加了Beep没有用!用Console.Beep(int,int)这个方法就可以了 。
另外,建议把提示出错的代码直接放入Catch中,提示鸣放的代码放入Try中 。
vb.net的一个问题蜂鸣器编程vb.net调用beep的话,有个API函数 , VB中的声明为
Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
调用方法是Beep 声音频率,持续时间(毫秒为单位)
比如 beep 2000,1000
如果是声卡编程的话,也有相应的API函数 , 比如你可以用DirectSound(也就是DirectX的一部分) , 功能比较强大 , 也很专业 。事实上,如果你使用的是专业级的声卡和音响设备,它可以在一定范围内回放出超出人耳听觉范围的声音 。当然也可以用简单一点的API , 以下是几个需要的函数:
Private Declare Function midiOutGetDevCaps Lib "winmm.dll" Alias "midiOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As MIDIOUTCAPS, ByVal uSize As Long) As Long
Private Declare Function midiOutGetNumDevs Lib "winmm" () As Integer
Private Declare Function MIDIOutOpen Lib "winmm.dll" Alias "midiOutOpen" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long
Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Private Declare Function midiOutGetErrorText Lib "winmm.dll" Alias "midiOutGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long
Private Const MAXERRORLENGTH = 128'max error text length (including NULL)
Private Const MIDIMAPPER = (-1)
Private Const MIDI_MAPPER = (-1)
'MIDIOUTCAPS结构描述vb.net调用beep了Musical Instrument Digital Interface(MIDI)输入设备的性能
Type MIDIOUTCAPS
wMid As Integer
wPid As Integer' 产品 ID
vDriverVersion As Long' 设备版本
szPname As String * 32' 设备 name
wTechnology As Integer' 设备类型
wVoices As Integer
wNotes As Integer
wChannelMask As Integer
dwSupport As Long
End Type
Public Sub note_on(ch As Integer, ByVal kk As Integer, v As Integer)
' 发音主函数 。参数分别为通道编号 , 音调,速度
Call midi_outshort(H90ch, kk, v)
End Sub
Sub midi_outshort(b1 As Integer, b2 As Integer, b3 As Integer)
Dim midi_error As Integer
midi_error = midiOutShortMsg(hMidi, b3 * H10000b2 * H100b1)
If Not midi_error = 0 Then
Call midi_outerr(midi_error)
End If
End Sub
Sub midi_outerr(ByVal midi_error As Integer)
Dim s As String
Dim x As Integer
s = Space(MAXERRORLENGTH)
x = midiOutGetErrorText(midi_error, s, MAXERRORLENGTH)
MsgBox s
End Sub
【vb.net调用beep vbnet console】vb.net调用beep的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet console、vb.net调用beep的信息别忘了在本站进行查找喔 。
推荐阅读
- 阿里动态口令服务器,阿里巴巴 口令
- 企业超级新媒体运营如何玩,公司的新媒体运营怎样开展
- 战舰即时战略游戏推荐,最新战舰游戏
- Flutter图片放大,flutter 图片加载
- 用Java编写服务端代码 用java编写服务端代码
- html5边框模糊圆角,html边框变圆点
- 变形金刚为什么重启了电视,变形金刚系列为什么失败
- 鲍鱼直播平台,鲍鱼平台钱提不出来
- vbnet怎么设置字体 vb设置字体为宋体的代码