Introduction
Did you ever want to seek through your DirectShow movie? Or get the current position of your movie and want to show that using your trackbar?
Background
Please read the related articles here:
Using the code
When you have created your graph like this:
f_MediaPositioning = CType(f_GraphManager, IMediaSeeking)
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)
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
you can have a separate sub that is called by a timer (whenever your graph is loaded and is in play/pause mode):
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)
You can use the IMediaSeeking
interface to control the rate of your movie.
History
No history yet.