Click here to Skip to main content
Licence CPOL
First Posted 14 Feb 2008
Views 18,841
Bookmarked 23 times

Seeking and getting the position snippets for DirectShow.NET

By | 14 Feb 2008 | Article
How to seek and get the position and duration for your DirectShow movie with VB.NET.

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) '(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

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jarno Burger

Other

Netherlands Netherlands

Member

Jarno Burger
i am videojockey for festivals.
i am getting fed up with the vj programs at the moment , so i am trying to go and write my own one.
 
if you wanna read some more stuff about directshow.net , then you can read some chunks of info on my blog , with some extra handy links to more articles and forums.
 
http://jarnoburger.blogspot.com/

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questiontwo video overlay question Pinmemberyhw1985040119:58 24 Apr '08  
I want to achieve two video overlay:
The establishment of a Transformfilter, and a heavy interface Inputpin come (based on CBaseInputPin), but the stack of incoming Inputpin receive pSample will keep receiving the reception, and did not follow the normal speed receiver, to identify the reason for this is that Permian Increase coming in this video Render does not control its speed, so it kept the moment to transmit data, I originally wanted to add sleep() in Receive function, but can not solve fundamental problems, the use of sleep() can not achieve the video overlay IMediaSeeking video interface, brought up a lot of problems. so do say, overlay video can't control the speed and seeking, the overlay video input to the main video throught the input pin (based on CBaseInputpin),how can I do ,please help
GeneralRe: two video overlay question PinmemberJarno Burger21:43 24 Apr '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 14 Feb 2008
Article Copyright 2008 by Jarno Burger
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid