VB.NET中播放背景音乐最简单的办法是什么啊?
发布网友
发布时间:2022-09-06 10:29
我来回答
共2个回答
热心网友
时间:2024-11-20 18:29
给你我的程序,自己研究一下吧,我也不是很明白。
Public Class Form1
Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hMole 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 i > 0 Then
MsgBox("可以播放声音", 64, "检测")
Else
MsgBox("不能播放声音", 64, "检测")
End If
End Sub
End Class
热心网友
时间:2024-11-20 18:30
通过html代码最简单
<bgsound src="文件路径" loop="-1">