音频背景播放Visual Basic时播放声音效果

时间:2014-09-04 14:55:04

标签: vb.net

我目前是制作VB的新手,我想问一下如何在播放背景音乐时播放声音效果,例如,在播放背景音乐时,当我点击按钮时会产生声音效果。就我而言,当我将鼠标悬停在按钮上时,当前的背景音乐停止并且声音效果执行,在我悬停鼠标后,背景音乐播放agaian

这是我的代码..

Public Class Form2

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
            AudioPlayMode.BackgroundLoop)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    Private Sub Button1_MouseHover(sender As Object, e As EventArgs) Handles Button1.MouseHover
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\Hawking.wav",
            AudioPlayMode.Background)
    End Sub

    Private Sub Button1_MouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
                AudioPlayMode.BackgroundLoop)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub

    Private Sub Button2_MouseHover(sender As Object, e As EventArgs) Handles Button2.MouseHover
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\Finn.wav",
            AudioPlayMode.Background)
    End Sub

    Private Sub Button2_MouseLeave(sender As Object, e As EventArgs) Handles Button2.MouseLeave
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
                AudioPlayMode.BackgroundLoop)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

    End Sub

    Private Sub Button3_MouseHover(sender As Object, e As EventArgs) Handles Button3.MouseHover
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\Homer.wav",
            AudioPlayMode.Background)
    End Sub

    Private Sub Button3_MouseLeave(sender As Object, e As EventArgs) Handles Button3.MouseLeave
        My.Computer.Audio.Play("C:\Users\android_kh5sy35fe2\Desktop\WWM\auswahlrunde_loop.wav",
                AudioPlayMode.BackgroundLoop)
    End Sub
End Class

感谢回复..干杯!

1 个答案:

答案 0 :(得分:0)

My.Computer.Audio.Play是唯一的(静态)。 您可以使用SoundPlayer,即,这样您就可以多次实例化它(对于每种声音)。

Dim music As String = "" ' *.wav file location
Dim media As New Media.SoundPlayer(music)
media.Play() ' Async, creates a new thread

Dim sound As String = "" ' *.wav file location
Dim media As New Media.SoundPlayer(sound)
media.PlaySync() ' Sync, locks the current thread