Hi,

I am atempting to make a time scroll bar (like the bar one would find at the bottom of video where you can jump to a specific time).

I am currently using a TTrackBar, with a TTimer that keeps updating the possition. The problem I am stuck with now, is alowing the user to jump to time. Using the TTrackBar.Change event is giving troubles, as it fires each time the Timer moves it forward aswell.

Is there a way to find out from where the event was fired? Or is there another component I can use?

Regards,
Robert

Since no one is responding to this...

I have always found the TTrackBar to be a bit cluncky. You can write your own from scratch (which I usually do), or simply derive a new one where you implement the OnMouseUp method, or (most simply) just check to see if the mouse button is down in your OnChange handler.

function IsButtonPressed( button: integer ): boolean;
  // button is VK_LBUTTON, VK_RBUTTON, or VK_MBUTTON
  var swapped: boolean;
  begin
  if GetSystemMetrics( SM_SWAPBUTTON ) <> 0 then
    case button of
      VK_LBUTTON: button := VK_RBUTTON;
      VK_RBUTTON: button := VK_LBUTTON
      end;
  result := (GetAsyncKeyState( button ) and $8000) <> 0
  end;

Hope this helps.

I had to do the same sort of thing within my project. Here's the code i used:

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
    if ABS(MediaPlayer1.Position - TrackBar1.Position) >= 1000 then
      begin
        MediaPlayer1.Position := TrackBar1.Position;
        TrackBar1.Position  := MediaPlayer1.Position;
        MediaPlayer1.Play;
      end;
end;

You have to remember that the MediaPlayer's timings are in ms so with the ">= 1000" it will only run if you change by more than a second. Since the player goes up in ms, playing the file wont trigger the code.

Hope this helps,

Tom

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.