808
社区成员




'窗体上7个命令按钮,1个图片框控件
Option Explicit
'Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
'定义DirectShow播放类
Dim PlayClass As cPlayFile
'后退
Private Sub Command1_Click()
Dim backCJL As Single
'PlayClass.PausePlay
backCJL = PlayClass.Position - 1
If backCJL >= 0 Then
PlayClass.Position = backCJL
Else
PlayClass.Position = 0
End If
End Sub
'前进
Private Sub Command2_Click()
Dim forwordCJL As Single
'PlayClass.PausePlay
forwordCJL = PlayClass.Position + 1
If forwordCJL <= PlayClass.Duration Then
PlayClass.Position = forwordCJL
Else
PlayClass.Position = PlayClass.Duration
End If
End Sub
'暂停
Private Sub Command3_Click()
PlayClass.PausePlay
End Sub
'停止
Private Sub Command4_Click()
PlayClass.StopPlay
End Sub
'关闭窗体
Private Sub Command5_Click()
Set PlayClass = Nothing
Unload Me
End Sub
'打开文件
Private Sub Command6_Click()
'打开文件
PlayClass.OpenFile "E:\中国航天\中国航天员首次出舱活动.mpg", Picture1
End Sub
'开始播放
Private Sub Command7_Click()
PlayClass.PlayFile
End Sub
Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.ScaleMode = 3
Set PlayClass = New cPlayFile
Command1.Caption = "后退"
Command2.Caption = "前进"
Command3.Caption = "暂停"
Command4.Caption = "停止"
Command5.Caption = "退出"
Command6.Caption = "打开"
Command7.Caption = "播放"
End Sub
Option Explicit
'文件播放类,只要装了解码器,就可播放大部分文件.
'需要引用ActiveMovie control type library,文件名:C:\WINDOWS\system32\quartz.dll
Dim pMC As FilgraphManager
Dim pVW As IVideoWindow
Dim pMP As IMediaPosition
Dim mFileName As String
Dim mObjPic As PictureBox
Public Sub OpenFile(ByVal sFilename As String, ByRef objPic As PictureBox)
'打开一个文件并处于暂停状态.
On Error GoTo ErrHandle
If sFilename = mFileName Then Exit Sub
mFileName = sFilename
Set mObjPic = objPic
pMC.RenderFile mFileName
On Error Resume Next
Set pVW = pMC
Set pMP = pMC
pVW.WindowStyle = CLng(&H6000000)
'设置图象区域大小
pVW.Left = 0: pVW.Top = 0
pVW.Width = mObjPic.ScaleWidth
pVW.Height = mObjPic.ScaleHeight
pVW.Owner = mObjPic.hWnd
Exit Sub
ErrHandle:
End Sub
Public Function PlayFile()
pMC.Run
End Function
Public Sub StopPlay()
'停止播放
pMC.Stop
End Sub
Public Sub PausePlay()
'暂停播放
pMC.Pause
End Sub
Private Sub Class_Initialize()
On Error Resume Next
Set pMC = New FilgraphManager
pMC.Stop
pMC.RenderFile ""
End Sub
Private Sub Class_Terminate()
Set pMP = Nothing
Set pVW = Nothing
Set pMC = Nothing
End Sub
'持续时间
Public Property Get Duration() As Single
On Error Resume Next
Duration = pMP.Duration
End Property
Public Property Let Duration(ByVal vNewValue As Single)
pMP.Duration = vNewValue
End Property
'位置
Public Property Get Position() As Single
On Error Resume Next
Position = pMP.CurrentPosition
End Property
Public Property Let Position(ByVal vNewValue As Single)
pMP.CurrentPosition = vNewValue
End Property
Public Property Get FileName() As String
FileName = mFileName
End Property
Public Property Let FileName(ByVal vNewValue As String)
mFileName = vNewValue
End Property
'以上代码为cPlayFile.cls
dim objPlayVideo as New cMCI
objPlayVideo.OpenFile("xxxx.mpg",Pic1.hWnd) '打开文件,并处于暂停状态
objPlayVideo.Position=500 '设置播放位置为500秒
dim objPlayVideo as New cPlayVideo
objPlayVideo.OpenFile("xxxx.mpg",Pic1) '打开文件,并处于暂停状态
objPlayVideo.Position=500 '设置播放位置为500秒