程序中插入一段mp3 的音乐
能否在VB的程序里面插入一段mp3的音乐, VB??插入音乐
[解决办法]
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
'Private Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long 'API判断数组为空或没有初始化
Private Const SND_ASYNC = &H1 '异步播放,否则就独占播放
Private Const SND_NODEFAULT = &H2 '不使用缺省声音
Private Const SND_MEMORY = &H4 '指向一个内存文件
Private Const SND_FILENAME = &H20000 '指向一个实际文件
Private Const SND_LOOP = &H8 '循环播放
Private Const SND_ALIAS_START = 0 '结束播放
'Dim B() As Byte
'Dim IniArray As Long '判断数组B()是否初始化
Private Function PlayMP3(ByVal Mp3Filename As String)
sndPlaySound Mp3Filename, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY Or SND_LOOP
MsgBox "按确定后解除警报!", vbOKOnly + vbCritical + vbSystemModal, "报警提示"
sndPlaySound vbNullString, SND_ALIAS_START
End Function
Private Sub Command1_Click()
PlayMP3 "D:\移动备份\yanni钢琴曲\Enchantment.mp3"
End Sub
'如果你的MP3在资源文件当中,应该采用播放内存资源的方法
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long 'API判断数组为空或没有初始化
Private Const SND_ASYNC = &H1 '异步播放,否则就独占播放
Private Const SND_NODEFAULT = &H2 '不使用缺省声音
Private Const SND_MEMORY = &H4 '指向一个内存文件
Private Const SND_FILENAME = &H20000 '指向一个实际文件
Private Const SND_LOOP = &H8 '循环播放
Private Const SND_ALIAS_START = 0 '结束播放
Dim B() As Byte
Dim IniArray As Long '判断数组B()是否初始化
Private Sub PlayMP3() '播放内存资源文件
B = LoadResData(101, "CUSTOM") '101是自定义资源号,CUSTOM是自定义的资源类型
IniArray = SafeArrayGetDim(B)
If IniArray > 0 Then
sndPlaySound B(0), SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY Or SND_LOOP
MsgBox "按确定后解除警报!", vbOKOnly + vbCritical + vbSystemModal, "报警提示"
End If
If IniArray > 0 Then sndPlaySound B(0), SND_ALIAS_START '停止播放
'sndPlaySound vbNullString, SND_ALIAS_START
End Sub
Private Sub Command1_Click()
PlayMP3
End Sub
'End Sub