是用windowmediaplayer空间
在工程——部件里面找到
应该在最下面
方法使用
windowmediaplayer1.url="e:\mp3\1.mp3"
放到form_load事件里面
拖进一个Windows
Media
Player控件,
设置其Visible属性为False
然后在Form_Load中用Windows
Media
Player加载你的背景音乐播放就OK了.
WindowsMediaPlayer1.Controls.play'播放
WindowsMediaPlayer1.Controls.stop'停止
WindowsMediaPlayer1.Controls.pause'暂停
你这样连续让它播放\停止\暂停,它最后就是停止了,当然没有声音啦
Private
Sub
WindowsMediaPlayer1_OpenStateChange(ByVal
NewState
As
Long)
WindowsMediaPlayer1.URL
=
"e:\wj\j.mp3"
WindowsMediaPlayer1.Controls.play
End
Sub
就可以了
你不是要加背景音乐吗?
Private
Sub
Form_Load()
WindowsMediaPlayer1.Visible
=
False
WindowsMediaPlayer1.URL
=
"e:\mp3\1.mp3"
End
Sub
这样,那个WindowsMediaPlayer不会出现在你的下雪画面中,又能实现背景音乐的播放了.
'下面仅以播放背景音乐为例
'在窗体代码中复制以下代码,并改变歌曲名称,运行后就会听到美妙的音乐了。
'====窗体代码部分====
Option Explicit
Dim a
Private Sub Form_Load()
Set a = CreateObject("wmplayer.ocx")
a.url = "E:\mp3\花好月圆.mp3" '你可在此改成你的乐曲
a.settings.playCount = 99999
End Sub
Private Sub Form_Unload(Cancel As Integer)
a.Controls.stop
a.Close
Set a = Nothing
End Sub
背景音乐干吗要用控件
api就行了
Private
Declare
Function
mciSendString
Lib
"winmm.dll"
Alias
"mciSendStringA"
(ByVal
lpstrCommand
As
String,
ByVal
lpstrReturnString
As
String,
ByVal
uReturnLength
As
Long,
ByVal
hwndCallback
As
Long)
As
Long
Dim
Res
As
Integer,
Ret
As
String
*
1024
Private
Sub
Form_Click()
Dim
Res
As
Integer,
Ret
As
String
*
1024
Res
=
mciSendString("play
"
&
"F:\我的音乐\DJ串烧一条龙.mp3",
Ret,
1024,
0)
End
Sub
Private
Sub
Form_QueryUnload(Cancel
As
Integer,
UnloadMode
As
Integer)
Res
=
mciSendString("close
all",
Ret,
1024,
0)
End
End
Sub