Skip to content

Trackbar

Moving the clip position immediately while the trackbar position is moved

When PlayerTrackBarSynchrone is enabled, moving the trackbar with the mouse continuously updates the position in the video clip, until the mouse button is released. When PlayerTrackBarSynchrone is disabled (default), the position is updated only when the mouse button is released.

This property requires the full trackbar implementation below (unless the PlayerTrackBar property is used in Delphi or C++Builder, see the note below).

Trackbar implementation

Note

With Delphi or C++Builder, a TTrackbar component can be placed on the form and assigned to the PlayerTrackBar property: it is then handled automatically, and the implementations below can be ignored.

Minimal trackbar implementation

The minimal trackbar implementation consists of the following steps:

  1. Place a trackbar on the form.
  2. Create a TVideoGrabber OnPlayerOpened event, and set the trackbar max position from this event by reading the PlayerFrameCount property.
  3. Create a TVideoGrabber OnPlayerUpdateTrackbarPosition event, and update the trackbar position with the FrameNumber parameter returned by this event.
  4. Create a trackbar OnChange or OnValueChanged event, and update PlayerFramePosition from this event with the current position of the trackbar.

With this minimal implementation, the trackbar may behave jerkily when its thumb is moved while the clip is playing, because the trackbar position is updated periodically in the background by the OnPlayerUpdateTrackbarPosition event.

Full trackbar implementation in Visual Studio

  1. Put a trackbar component on the form.
  2. Create a TVideoGrabber OnPlayerOpened event that sets the min and max positions of the trackbar, e.g.:

    private void axVideoGrabberNET1_OnPlayerOpened(object sender, System.EventArgs e)
    {
        tbrPlayer.Minimum = 0;
        tbrPlayer.TickFrequency = 1;
        tbrPlayer.Maximum = (int) axVideoGrabberNET1.PlayerFrameCount;
    }
    
  3. Create a TVideoGrabber OnPlayerUpdateTrackbarPosition event that updates the trackbar position, e.g.:

    private void axVideoGrabberNET1_OnPlayerUpdateTrackbarPosition(object sender, Axvidgrab_NET.IVideoGrabberNETEvents_OnPlayerUpdateTrackbarPositionEvent e)
    {
        tbrPlayer.Value = (int) e.frameNumber;
    }
    
  4. Create a trackbar OnChange or OnValueChanged event that updates the TVideoGrabber PlayerFramePosition, e.g.:

    private void tbrPlayer_ValueChanged(object sender, System.EventArgs e)
    {
        axVideoGrabberNET1.PlayerFramePosition = tbrPlayer.Value;
    }
    
  5. Create trackbar OnMouseDown, OnMouseUp, OnKeyDown and OnKeyUp events that invoke NotifyPlayerTrackbarAction with the corresponding TTrackbarAction parameter, e.g.:

    private void tbrPlayer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        axVideoGrabberNET1.NotifyPlayerTrackbarAction (vidgrab_NET.TxTrackbarAction.tba_MouseDown);
    }
    
    private void tbrPlayer_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        axVideoGrabberNET1.NotifyPlayerTrackbarAction (vidgrab_NET.TxTrackbarAction.tba_MouseUp);
    }
    
    private void tbrPlayer_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        axVideoGrabberNET1.NotifyPlayerTrackbarAction (vidgrab_NET.TxTrackbarAction.tba_KeyDown);
    }
    
    private void tbrPlayer_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        axVideoGrabberNET1.NotifyPlayerTrackbarAction (vidgrab_NET.TxTrackbarAction.tba_KeyUp);
    }
    

Then run the application: the trackbar works properly, even when the thumb is moved while the clip is playing.