用时钟跟踪 STATUS POSITION 指令读取媒体目前的播放位置。 DIM S AS STRING S=STRING(256,0) MCISENDSTRING “STATUS MYMEDIA position",S,LEN(S),0 'VAL(S)即等于目前播放位置。看其是否等于媒体的总长度。 DIM S AS STRING S=STRING(256,CHR(0)) MCISENDSTRING “STATUS MYMEDIA length",s,len(s),0 'VAL(S)即等于媒体的总长度。
’**窗体** Option ExplicitPrivate Sub Command1_Click() Dim PathName As String, S As String, ShortPathName As String Dim ret As Long
PathName = File1.Path If Right(PathName, 1) <> "\" Then PathName = PathName & "\" PathName = PathName & File1.FileName
S = String(LenB(PathName), Chr(0)) GetShortPathName PathName, S, Len(S) ShortPathName = Left(S, InStr(S, Chr(0)) - 1) mciSendString "close MyMedia", vbNullString, 0, 0 ret = mciSendString("open " & ShortPathName & " alias MyMedia", vbNullString, 0, 0) If ret = 0 Then Caption = "播放多媒体文件 -- 已开启" & PathName
End SubPrivate Sub Command2_Click() mciSendString "play MyMedia", vbNullString, 0, 0 End SubPrivate Sub Command3_Click() mciSendString "pause MyMedia", vbNullString, 0, 0 End SubPrivate Sub Command4_Click() Dim S As String
mciSendString "seek MyMedia to start", vbNullString, 0, 0
HScroll1.Value = Val(S) End SubPrivate Sub Command5_Click() mciSendString "close MyMedia", vbNullString, 0, 0 Caption = "播放多媒体文件 -- 文件已关闭!" HScroll1.Enabled = False End SubPrivate Sub Dir1_Change() File1.Path = Dir1.Path End SubPrivate Sub Drive1_Change() Dir1.Path = Drive1.Drive End SubPrivate Sub Form_Unload(Cancel As Integer) mciSendString "close MyMedia", vbNullString, 0, 0 End SubPrivate Sub HScroll1_Change() Dim S As String
S = String(256, 0) mciSendString "status MyMedia mode", S, Len(S), 0 If Left(S, 7) = "playing" Or Left(S, 2) = "播放" Then Exit Sub
mciSendString "seek MyMedia to " & HScroll1.Value, vbNullString, 0, 0 End SubPrivate Sub Timer1_Timer() Dim S As String, ret As Long
S = String(256, 0) ret = mciSendString("status MyMedia mode", S, Len(S), 0) If ret <> 0 Or Left(S, 7) = "stopped" Or Left(S, 2) = "停止" Then Exit Sub End If
HScroll1.Value = Val(S) End Sub ‘***模块********Option ExplicitDeclare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
DIM S AS STRING
S=STRING(256,0)
MCISENDSTRING “STATUS MYMEDIA position",S,LEN(S),0
'VAL(S)即等于目前播放位置。看其是否等于媒体的总长度。
DIM S AS STRING
S=STRING(256,CHR(0))
MCISENDSTRING “STATUS MYMEDIA length",s,len(s),0
'VAL(S)即等于媒体的总长度。
Option ExplicitPrivate Sub Command1_Click()
Dim PathName As String, S As String, ShortPathName As String
Dim ret As Long
PathName = File1.Path
If Right(PathName, 1) <> "\" Then PathName = PathName & "\"
PathName = PathName & File1.FileName
S = String(LenB(PathName), Chr(0))
GetShortPathName PathName, S, Len(S)
ShortPathName = Left(S, InStr(S, Chr(0)) - 1) mciSendString "close MyMedia", vbNullString, 0, 0
ret = mciSendString("open " & ShortPathName & " alias MyMedia", vbNullString, 0, 0)
If ret = 0 Then Caption = "播放多媒体文件 -- 已开启" & PathName
S = String(256, Chr(0))
mciSendString "status MyMedia length", S, Len(S), 0
HScroll1.Max = Val(S)
HScroll1.Min = 0
HScroll1.SmallChange = IIf(HScroll1.Max \ 100 > 0, HScroll1.Max \ 100, 1)
HScroll1.LargeChange = IIf(HScroll1.Max \ 10 > 0, HScroll1.Max \ 10, 1)
HScroll1.Enabled = True
End SubPrivate Sub Command2_Click()
mciSendString "play MyMedia", vbNullString, 0, 0
End SubPrivate Sub Command3_Click()
mciSendString "pause MyMedia", vbNullString, 0, 0
End SubPrivate Sub Command4_Click()
Dim S As String
mciSendString "seek MyMedia to start", vbNullString, 0, 0
S = String(256, 0)
mciSendString "status MyMedia position", S, Len(S), 0
HScroll1.Value = Val(S)
End SubPrivate Sub Command5_Click()
mciSendString "close MyMedia", vbNullString, 0, 0
Caption = "播放多媒体文件 -- 文件已关闭!"
HScroll1.Enabled = False
End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub Form_Unload(Cancel As Integer)
mciSendString "close MyMedia", vbNullString, 0, 0
End SubPrivate Sub HScroll1_Change()
Dim S As String
S = String(256, 0)
mciSendString "status MyMedia mode", S, Len(S), 0
If Left(S, 7) = "playing" Or Left(S, 2) = "播放" Then Exit Sub
mciSendString "seek MyMedia to " & HScroll1.Value, vbNullString, 0, 0
End SubPrivate Sub Timer1_Timer()
Dim S As String, ret As Long
S = String(256, 0)
ret = mciSendString("status MyMedia mode", S, Len(S), 0)
If ret <> 0 Or Left(S, 7) = "stopped" Or Left(S, 2) = "停止" Then
Exit Sub
End If
S = String(256, 0)
mciSendString "status MyMedia position", S, Len(S), 0
HScroll1.Value = Val(S)
End Sub
‘***模块********Option ExplicitDeclare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long