Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

这段代码中,如何控制音乐播放时长?

gemeng  发表于:2016-08-16 09:09:32  
复制

代码是我们论坛示例中的,如果更换其它音乐时,却无法调节播放时间长度,求帮助,感谢!

目前只重复滴滴滴的声音


'Sound APIs
Private Declare Function apiPlaySound Lib "Winmm.dll" Alias "sndPlaySoundA" _
                                      (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

'AVI APIs
Private Declare Function apimciSendString Lib "Winmm.dll" Alias "mciSendStringA" _
                                          (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
                                           ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Private Declare Function apimciGetErrorString Lib "Winmm.dll" _
                                              Alias "mciGetErrorStringA" (ByVal dwError As Long, _
                                                                          ByVal lpstrBuffer As String, ByVal uLength As Long) As Long


Function fPlayStuff(ByVal strFilename As String, _
                    Optional intPlayMode As Integer) As Long
'MUST pass a filename _with_ extension
'Supports Wav, AVI, MID type files
    Dim lngRet As Long
    Dim strTemp As String

    Select Case LCase(fGetFileExt(strFilename))
    Case "wav":
        If Not IsMissing(intPlayMode) Then
            lngRet = apiPlaySound(strFilename, intPlayMode)
        Else
            MsgBox "Must specify play mode."
            Exit Function
        End If
    Case "avi", "mid":
        strTemp = String$(256, 0)
        lngRet = apimciSendString("play " & strFilename, strTemp, 255, 0)
    End Select
    fPlayStuff = lngRet
End Function
Function fStopStuff(ByVal strFilename As String)
'Stops a multimedia playback
    Dim lngRet As Long
    Dim strTemp As String
    Select Case LCase(fGetFileExt(strFilename))
    Case "Wav":
        lngRet = apiPlaySound(0, pcsASYNC)
    Case "avi", "mid":
        strTemp = String$(256, 0)
        lngRet = apimciSendString("stop " & strFilename, strTemp, 255, 0)
    End Select
    fStopStuff = lngRet
End Function

Private Function fGetFileExt(ByVal strFullPath As String) As String
    Dim intPos As Integer, intLen As Integer
    intLen = Len(strFullPath)
    If intLen Then
        For intPos = intLen To 1 Step -1
            'Find the last \
            If Mid$(strFullPath, intPos, 1) = "." Then
                fGetFileExt = Mid$(strFullPath, intPos + 1)
                Exit Function
            End If
        Next intPos
    End If
End Function

Function fGetError(ByVal lngErrNum As Long) As String
' Translate the error code to a string
    Dim lngx As Long
    Dim strErr As String

    strErr = String$(256, 0)
    lngx = apimciGetErrorString(lngErrNum, strErr, 255)
    strErr = left$(strErr, Len(strErr) - 1)
    fGetError = strErr
End Function
Function fatest()
    Dim a As Long
    a = fPlayStuff("C:\winnt\clock.avi")
    'a = fStopStuff("C:\winnt\clock.avi")
End Function



Private Sub Form_Load()
    Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
    Call fPlayStuff(CurrentProject.Path & "\WAV\报警声音.wav", 1)
End Sub


点击下载此附件

 

Top
gemeng 发表于:2016-08-16 13:01:36

怎么没有高手帮忙啊?



gemeng 发表于:2016-08-16 15:52:39

不好意思,竟然忘了转换格式了!问题已解决!



麥田 发表于:2016-08-16 16:02:02


麥田 发表于:2016-08-16 16:02:50
【给力示例】发声报警-带声音的自动提醒示例[Access软件网]
http://www.accessoft.com/article-show.asp?id=5394

总记录:4篇  页次:1/1 9 1 :