如何在access中播放MIDI、AVI、WAV文件-黄海
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


如何在access中播放MIDI、AVI、WAV文件

发表时间:2007/5/15 评论(0) 浏览(8226)  评论 | 加入收藏 | 复制
   
摘 要:在ACCESS中播放MIDI、AVI、WAV文件的详细代码
正 文:
使用下面的函数可以实现,注意:表达式中的文件名一定为完整文件名,包括扩展名。


'****************** Code Start *********************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Public Const pcsSYNC = 0 ' wait until sound is finished playing
Public Const pcsASYNC = 1 ' don't wait for finish
Public Const pcsNODEFAULT = 2 ' play no default sound if sound doesn't exist
Public Const pcsLOOP = 8 ' play sound in an infinite loop (until next apiPlaySound)
Public Const pcsNOSTOP = 16 ' don't interrupt a playing sound

'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

'****************** Code End *********************


'特别说明:本文原创作者:Dev Ashish


Access软件网交流QQ群(群号:198465573)
 
 相关文章
用MS Animation控件实现播放*.avi动画文件   【竹笛  2005/1/5】
[荐]MIDI电子琴示例(Mde)  【  2008/6/27】
midi简易电子琴  【一杯绿茶  2009/6/2】
access播放wav音频文件  【煮茶论道  2011/9/6】
access中除第三方控件外播放GIF的三种方法  【叶海峰  2012/2/6】
用access播放swf文件  【大漠风  2012/12/18】
在Access窗体中播放动态Gif  【纵云梯  2013/6/27】
常见问答
技术分类
相关资源
文章搜索
关于作者

黄海

文章分类

文章存档

友情链接