VB mciSendString(Api)怎样实现循环播放音乐?
Playsound是播放wav音乐的,但楼主的是mp3
应该用API:mciSendString函数来播放:
Call mciSendString("open " & App.Path & "\music\1.mp3", vbNullString, 0, 0)
Call mciSendString("play " & App.Path & "\music\1.mp3" & " repeat", vbNullString, 0, 0) '循环播放
方法一:Do while 1……Loop 重复
Private Declare Function mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click()
Do While 1
Call mciSendStringA("open C:/1.mp3 type MPEGVideo alias MP3", vbNullString, 0, 0) '打开1.mp3
Call mciSendStringA("play MP3 wait", vbNullString, 0, 0)
Call mciSendStringA("close MP3", vbNullString, 0, 0)
Loop
End Sub
方法2:mci指令repeat 重复(推荐,楼上的,你提供的代码可以改进,里面C:/1.mp3可以使用假名MP3(或其他),用起来更方便)
Private Declare Function mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click()
Call mciSendStringA("open C:/1.mp3 type MPEGVideo alias MP3", vbNullString, 0, 0) '打开1.mp3
Call mciSendStringA("play MP3 repeat", vbNullString, 0, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call mciSendStringA("close MP3", vbNullString, 0, 0)
End Sub
Private Declare Function mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click()
Do While 1
Call mciSendStringA("open C:/1.mp3 type MPEGVideo alias MP3", vbNullString, 0, 0) '打开1.mp3
Call mciSendStringA("play MP3 wait", vbNullString, 0, 0)
Call mciSendStringA("close MP3", vbNullString, 0, 0)
Loop
End Sub
方法2:mci指令repeat 重复(推荐,楼上的,你提供的代码可以改进,里面C:/1.mp3可以使用假名MP3(或其他),用起来更方便)
Private Declare Function mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click()
Call mciSendStringA("open C:/1.mp3 type MPEGVideo alias MP3", vbNullString, 0, 0) '打开1.mp3
Call mciSendStringA("play MP3 repeat", vbNullString, 0, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call mciSendStringA("close MP3", vbNullString, 0, 0)
End Sub
http://tieba.baidu.com/f?kz=381071536
VB吧里已经有答案,另mciSendString的字符串参数详细情况参考下面的链接
才雨舒肝: 录音前,用以下语句初始化 1.设为8位:mciSendString "set wave bitpersample 8", "", 0, 0 2.设为11025Hz mciSendString "set wave samplespersec 11025", "", 0, 0 3.设为立体声:mciSendString "set wave channels 2", "", 0, 0 4....
酉阳土家族苗族自治县15845102830: 在vb中如何用api函数mcisendstring一边进行录音一边进行播放,也就说录音与播放是同步的. - ?
才雨舒肝: 这个函数我一般是用来做软件背景音乐用,用的多了
酉阳土家族苗族自治县15845102830: VB mciSendString(Api)怎样实现循环播放音乐? - ?
才雨舒肝: 方法一:Do while 1……Loop 重复Private Declare Function mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long Private ...
酉阳土家族苗族自治县15845102830: vb mcisendstring声音大小(最小和最大是什么?)?
才雨舒肝: vb6.0: min:0;Max:63534 获取麦克风音量大小值 mciSendString "status movie volume", V, 0, 0 '(move 你自己定义的什么就改为什么) 返回的V就是音量的大小 当前播放音乐的音量,即喇叭的音量;我是用vb2005做的,供参考 Private Declare ...
酉阳土家族苗族自治县15845102830: VB mcisendstring定位播放 - ?
才雨舒肝: 设置播放位置.(需事先设定时间格式),格式:Seek 设备名 [to 位置 | to start | to end] Dim P1 as Long, P2 as Long P1 = 100: P2 = 3000 mciSendString "seek movie to ", P1, 0, 0 'P1是当前起始位置,单位:毫秒mciSendString "seek movie ...
酉阳土家族苗族自治县15845102830: vb6中如何添加声音 - ?
才雨舒肝: 这个你要使用vb 的api函数来实现:mcisendstring具体的例子:Option Explicit Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal ...
酉阳土家族苗族自治县15845102830: mciSendString得到歌曲时长 VB - ?
才雨舒肝: Private Sub Command1_Click() Dim r As String r = String(256, Chr(0)) Dim f As String f = "d:\AOIV.mp3"'文件名根据自己需要改 mciSendString "Status " & f & " length", r, 256, 0 Dim m As Long m = Val(r) \ 1000 \ 60 Dim c As Double c = Val(r) / 1000 - m * 60 MsgBox "长度" & m & "分" & c & "秒" End Sub
酉阳土家族苗族自治县15845102830: vb 我想用mcisendstring 函数添加音乐播放效果,怎么不出声啊 - ?
才雨舒肝: 看Complay_Click 你直接就Play了,当然不行,要先打开文件 Call mciSendString("open " & file, vbNullString, 0, 0) '用Open打开音乐文件'Call mciSendString("play " & file & " repeat", vbNullString, 0, 0) '循环播放 Call mciSendString("play " & file , vbNullString, 0, 0) '只是播放一次
酉阳土家族苗族自治县15845102830: (vb编程) - --如何播放声音或视频 - ?
才雨舒肝: 问题其实可以如此的解决:使用vb的api函数:mcisendstringPublic Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As ...
酉阳土家族苗族自治县15845102830: vb mciSendString不发声 - ?
才雨舒肝: 你的代码写错了 先要用"open"命令打开设备,再用“play”命令播放 给个参考给你 sub play(byval musicpath as string) call mciSendString ("close OpenFile", vbNullString, 0, 0) Call mciSendString("open " & musicpath & " alias OpenFile type MPEGVideo", vbNullString, 0, 0) call mciSendString("play OpenFile", vbNullString, 0, 0) end sub 调用方法: play 音乐文件路径