Visual Basic.NET 7.x (2002/03)DirectXVisual Basic 9 (2008)Visual Basic 8 (2005)中级开发Visual StudioVisual Basic
寻找并获取 DirectShow.NET 的位置片段





0/5 (0投票)
如何使用 VB.NET 寻找并获取 DirectShow 电影的位置和时长。
引言
你是否想过在 DirectShow 电影中进行跳转?或者获取当前电影的位置并使用你的滑块显示它?
背景
请阅读以下相关文章
- CodeProject -> DirectShow 示例
- C# 与 VB.NET 之间的转换
- Informikon -> DirectShow
- MSDN 论坛 DirectShow
- MSDN 新闻组 DirectX Video
- Sourceforge Directshow.Net 论坛
- The March Hare -> DirectShow
- TheZBuffer -> DirectShow + Direct3D
使用代码
当你像这样创建你的图表时
f_MediaPositioning = CType(f_GraphManager, IMediaSeeking) '(f_graphmanager is the base)
Public Event Movie_Playhead_Moved(ByVal frame as long, duration as long)
Public Sub Graph_Seek(ByVal frame As Long)
If FilterGraphState = FilterGraphStateEnum.Ready Then
Try
Dim hr As Integer
Dim duration As Long
hr = f_MediaPositioning.GetDuration(duration) : DsError.ThrowExceptionForHR(hr)
hr = f_MediaPositioning.SetPositions(frame, _
AMSeekingSeekingFlags.AbsolutePositioning, _
duration, AMSeekingSeekingFlags.AbsolutePositioning)
RaiseEvent Movie_Playhead_Moved(frame , duration)
DsError.ThrowExceptionForHR(hr)
Catch ex As Exception
ThrowError("error sub graph_seek : ", ex)
'throwerror is my custom messagehandler
End Try
Else
ThrowError("not ready to do seeking")
End If
End Sub
Private Sub HeANewPlayheadEvent(byval frame as long, _
byval duration as long) handles me.Movie_Playhead_Moved
Invoke_trackbar_playhead_update(frame, duration)
End Sub
Public Sub Invoke_trackbar_playhead_update(ByVal frame as long, duration as long)
If Me.TrackbarPlayhead.InvokeRequired Then
Dim del As New Delegate_Trackbar_Playhead_Update(_
AddressOf Process_Trackbar_playhead_update)
del.Invoke(frame,duration)
Else
Process_Trackbar_playhead_update(frame,duration)
End If
End Sub
Private Sub Process_Trackbar_playhead_update(ByVal frame As long, ByVal duration As long)
If TrackbarPlayhead.Value <> frame Then
TrackbarPlayhead.Maximum = Cint(duration / 1000)
TrackbarPlayhead.Value = CInt(frame / 1000)
TrackbarPlayhead.TickFrequency = CInt(duration / 10)
TrackbarPlayhead.Update()
Application.DoEvents()
End If
End Sub
你可以有一个单独的子程序,该子程序由定时器调用(每当你的图表加载并处于播放/暂停模式时)
Dim hr As Integer:Dim frame As Long
hr = f_MediaPositioning.GetCurrentPosition(frame) : DsError.ThrowExceptionForHR(hr)
hr = f_MediaPositioning.GetDuration(duration) : DsError.ThrowExceptionForHR(hr)
Invoke_trackbar_playhead_update(frame, duration)
你可以使用 IMediaSeeking
接口来控制电影的速率。
历史
目前还没有历史记录。