Mp3 音乐不能融入 VB 的窗体之中,只能是一个外部文件。
给你几个子程序,可能有用——
' 点击:工程 → 部件,勾选:Microsoft Multimedia Control 6.0
' ActiveX 控件文件:MIC32.OCX
' 控件名称: MMControl1
Option Explicit ' 变量必须先定义
Dim mPath$, cWJ$, nTP%
Private Sub 播放音乐()
Dim cTS$ ' 需用全局变量【cWJ】
If Dir(cWJ, vbHidden) = "" Then
cTS = "没有发现音乐文件【"
cTS = cTS & cWJ & "】。"
MsgBox cTS, 0 + 64, "系统提示"
Else
MMControl1.Command = "Close"
With MMControl1
.Visible = True ' MMControl1 可见
.FileName = cWJ ' 指定声音文件
.Command = "Open" ' 打开多媒体文件
.Command = "Play" ' 播放多媒体文件
End With
End If
End Sub
Private Sub Win7音量()
' Windows_7_音量合成器
Dim Wjm$, cTS$
Wjm = "C:\Windows\System32\SNDVOL.EXE"
If Dir(Wjm) = "" Then
cTS = "Windows7 操作系统的音量合成器"
cTS = cTS & "驱动文件被损坏!"
cTS = cTS & vbCrLf & vbCrLf
cTS = cTS & "请想办法找回来后再试。"
MsgBox cTS, 0 + 64, "系统提示"
Else
Shell Wjm, 1
End If
End Sub
Private Sub 暂停_Click()
MMControl1.Command = "Pause"
End Sub
Private Sub 继续_Click()
MMControl1.Command = "Play"
End Sub
Private Sub 背景_Click()
Dim cTS$
cWJ = mPath & "ZiYuan\背景音乐.Mp3"
Call 播放声音
End Sub
' 重复播放音乐 -----------------------------
Private Sub MMControl1_Done( _
NotifyCode As Integer)
If NotifyCode = 1 Then
MMControl1.From = 0
MMControl1.Command = "PLAY"
End If
End Sub
' 程序一运行就播放背景音乐 -------------
Private Sub Form_Load()
' 播放背景音乐 -----------------------------
mPath = App.Path ' 获取程序运行绝对路径
If Right(mPath, 1) <> "\" Then mPath = mPath & "\"
cWJ = mPath & "ZiYuan\背景音乐.Mp3"
Call 播放声音
End Sub