新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
My.Computer.Audio.Play("SoundFile.wav")
成都创新互联主要从事网站设计、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务奉贤,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220
SoundFile.wav是你要播放的声音文件的路径
准备采集 哪方面的内容呢?
我使用 VB 编写了 搜狐论坛的图片采集,搜狐博客的文档下载,百度和谷歌的图片搜索采集,和讯博客的自动访问,某一投票的自动投票成寻。
你采集哪方面的数据呢?可以交流一下。
1.用Win32 API PlaySound
PlaySound位于"winmm.dll"中,可以根据输入参数的不同,播放WAV类型的音乐。在VB.NET中调用跟VB6中差不多:
先声明:
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
具体还有很多常量,不一一列举,下面是播放一个wav文件的例子
Dim mstrfileName As String = "c:\eagle2.wav"
PlaySound(mstrfileName, 0, SND_FILENAME)
注意上面的播放是非同步的,就是说它并不会播放完毕才结束。如果把上面的代码写在一个Button.Click的事件处理程序中,第二次点击的时候它会打断第一次的播放,重新开始。
当然我们也可以调用系统的声音:
PlaySound("SystemStart", 0, SND_ALIAS Or SND_SYNC)
' 以同步的方式调用系统启动时候的声音。
2. 调用媒体播放器控件
VB.NET中并没有提供媒体播放器的.NET组件,没办法我们还是调用以前Com组件Windows Media Player。当然除了声音外,还可以播放视频文件。
首先把媒体播放器控件加到工具栏中,调用还是简单的写一下吧:)
Private Sub playMediaFile(ByVal mediaFileName As String)
With MediaPlayer1
.Stop()
.FileName = "c:\mp3\爱不爱我.mp3"
.Play()
End With
End Sub
方法一:调用系统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可以直接调用API播放声音文件,不需要你二进制来读取声音文件的。
Private
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA"
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub PlayWavFile(strFileName As String, PlayCount As Long, JianGe As Long)
'strFileName 要播放的文件名(带路径)
'playCount 播放的次数
'JianGe 多次播放时,每次的时间间隔
If Len(Dir(strFileName)) = 0 Then Exit Sub
If PlayCount = 0 Then Exit Sub
If JianGe 1000 Then JianGe = 1000
DoEvents
sndPlaySound strFileName, 16 + 1
Sleep JianGe
Call PlayWavFile(strFileName, PlayCount - 1, JianGe)
End Sub
Private Sub Form_Click()
PlayWavFile "C:\aaa.wav", 1, 1000 '参数:播放文件,播放次数,播放间隔
End Sub
A simple Sound Recorder~
1. Add Three buttons (button1, button2, button3) and a label (label1) to the form.
2. Set the Text of Button1 to Start, Button2 to Stop, and Button3 to Play.
3. Add this code:
Public Class Form1
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
mciSendString("record recsound", "", 0, 0)
Label1.Text = "Recording..."
Label1.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = True
mciSendString("save recsound c:\recsound.wav", "", 0, 0)
mciSendString("close recsound", "", 0, 0)
MsgBox("File Created: C:\recsound.wav")
Label1.Text = "Stopped..."
Label1.Visible = False
My.Computer.Audio.Stop()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Label1.Text = "Playing..."
Label1.Visible = True
My.Computer.Audio.Play("c:\recsound.wav", AudioPlayMode.Background)
End Sub
End Class