* 调用示例:
* ------------------------------------------------
* 1、播放媒体文件(只播一次)
= PlayMicList( [Z:\OKSong\高胜美\记得我们有约.mpg], .F. )
Return
* 2、播放文件列表(循环播放)
Local lcSysPath
lcSysPath = Addb(Justpath(Sys(16,1)))
= PlayMicList( Filetostr( Addb(lcSysPath)+[PlayMicList.txt] ), .T. )
Return
* ------------------------------------------------
* 主体代码:
* ------------------------------------------------
Function PlayMicList( tcPlayListStr, tlISRePlayMic )
* ------------------------------------------------
* 功能: 主函数,播放媒体文件或文件列表串
* 参数: tcPlayListStr - 播放文件列表字符串,文件间用回车换行符分隔
*
tISRePlayMic
- 是否循环播放列表,默认为.T.
* ------------------------------------------------
If Type([tcPlayListStr])=[C]
If !Empt(tcPlayListStr)
If Vartype(_Screen.MicTime) = [O]
_Screen.RemoveObject([MicTime])
Endif
_Screen.AddObject([MicTime], [MicTime])
With _Screen.MicTime
If Para()=2 And Vartype(tlISRePlayMic) = [L]
.ISRePlayMic = tlISRePlayMic
Endif
Local lcCR, lcList, lnFile, liFile, lcFile
lcCR = Chr(13) + Chr(10)
lcList = lcCR + tcPlayListStr + lcCR
lnFile = Occu( lcCR, lcList ) - 1
For liFile = 1 To lnFile
lnBeg = At( lcCR, lcList, liFile ) + 2
lnEnd = At( lcCR, lcList, liFile + 1 )
lcFile = Subs( lcList, lnBeg, lnEnd-lnBeg )
If File(lcFile)
If MicCanBeOpen(lcFile) > 0
.nMicCount = .nMicCount + 1
Dime .aMicList(.nMicCount)
.aMicList(.nMicCount) = lcFile
Endif
Endif
Endfor
= SendMciString( [Close MICTEMP] )
= SendMciString( [Close MICVFPPLAY] )
.Enabled = .T.
Endwith
Endif
Endif
Endfunc
Function MicCanBeOpen( tcFileName )
tcFileName = Iif(Type([tcFileName])=[C], tcFileName, [])
Local lnMicLength
lnMicLength = 0
If SendMciString( [Open ] + GetShortFile(tcFileName) + [ Alias MICTEMP] )#[MicError]
lnMicLength = Val( SendMciString([Status MICTEMP Length]) ) && 取媒体长度
= SendMciString( [Close MICTEMP] )
Endif
Return lnMicLength
Endfunc
Function OpenAndPlayMicFile( tcPlayFile )
tcPlayFile = Iif(Type([tcPlayFile])=[C],tcPlayFile,[])
If !Empt(tcPlayFile) And File(tcPlayFile)
Local lcShotFile, lnVideoHwnd
lcShotFile = GetShortFile(tcPlayFile)
= SendMciString( [Close MICVFPPLAY] )
= SendMciString( [Open ] + lcShotFile + [ Alias MICVFPPLAY] )
lnMicLength = Val(SendMciString( [Status MICVFPPLAY Length] ) )
= SendMciString( [Play MICVFPPLAY From 0] )
Endif
Endfunc
Function SendMciString( tcMCIcmd )
Declare Integer mciSendString
In WINMM String, String, Integer,Integer
Declare Integer mciGetErrorString In WINMM Integer, String, Integer
Local lcRetStr, lcErrStr, lnRetVal
lcRetStr = Space( 80)
lnRetVal = mciSendString( tcMCIcmd, @lcRetStr, Len(lcRetStr), 0 )
If lnRetVal = 0
Return Trim(Strtran(lcRetStr,Chr(0),[]))
Else
Return [MicError]
Endif
Endfunc
Function GetShortFile( tcPathFileName )
tcPathFileName = Iif(Type([tcPathFileName])=[C],tcPathFileName,[])
Local lcRetuShotFile, lnRetuShotFile
Declare Integer GetShortPathName In kernel32 String, String, Integer
lcRetuShotFile = Space(255)
lnRetuShotFile = GetShortPathName(tcPathFileName, @lcRetuShotFile, Len(tcPathFileName))
lcRetuShotFile = Iif(Empt(lcRetuShotFile), tcPathFileName, Left(lcRetuShotFile, lnRetuShotFile) )
Return lcRetuShotFile
Endfunc
Define Class MicTime As Timer
Interval = 1000
Name = [MicTime]
Enabled = .F.
nMicCount = 0
nMicValue = 0
ISPlayInit = .T.
ISRePlayMic = .T.
Dime aMicList(1)
aMicList(1) = []
Procedure Timer
With This
lnMicLength = Val(SendMciString( [Status MICVFPPLAY Length] ) )
&& 取媒体总长度
lnMicPosition = Val(SendMciString( [Status MICVFPPLAY Position]) ) && 取当前的播放位置
If lnMicPosition >= lnMicLength
= SendMciString( [Close MICVFPPLAY] )
If .nMicCount = 0
.Enabled = .F.
Else
If .ISPlayInit
.nMicValue = 1
.ISPlayInit = .F.
= OpenAndPlayMicFile( .aMicList(.nMicValue) )
Else
If .nMicCount <= .nMicValue
If .ISRePlayMic
.nMicValue = 1
= OpenAndPlayMicFile( .aMicList(.nMicValue) )
Else
.Enabled = .F.
Endif
Else
.nMicValue = .nMicValue + 1
= OpenAndPlayMicFile( .aMicList(.nMicValue) )
Endif
Endif
Endif
Endif
Endwith
Endproc
Enddefine