我正在编写随机播放单一频率的窗体。我能够播放音频,但音频正在通过计算机本身播放。这是我用来播放音频的代码:
Private soundFileNames() As Integer = {100, 4000, 9050, 15500}
Private Sub playNextFreq_Click(sender As Object, e As EventArgs) Handles playNextFreq.Click
'Random index is chosen using a random number generator
index = CInt(Int(((soundFileNames.Length - 1) * Rnd()) + 0))
'Declares where the audio will be playing from.
Dim strLocationAndNameOfFile As String = soundFileNames(index).ToString() + ".wav"
'Verify the files existence
If IO.File.Exists(strLocationAndNameOfFile) Then
My.Computer.Audio.Play(strLocationAndNameOfFile, AudioPlayMode.Background)
Else
MsgBox(strFileError)
End If
end sub
我很抱歉格式错误。但是,我希望你能得到一般的想法。
My.Computer.Audio.Play(..)是我可以通过点击播放音频的唯一方法。