progressbar and mediaplaye and onclick - Help

Hello Guys,

I have a form where I dropped a mediaplay and a progressbar.

According to mediaplay is playing the music, my progressbar display the line time execution.

Then, when the music is about 50% played, my progressbar is also 50% fulfilled.

I'd like to know how to click on the progressbar, any part of it and back or forward the music at the position

where it was clicked.

I don't know how to do that.

Thanks
Alex
LVL 1
hidrauAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
the position property of the progressbar should be updated to the mouse position
you could use relative coordinates
...ow ... it doesn't have a click event

i'll check and get back on this
0
hidrauAuthor Commented:
ok Geert Gruwez, thanks
0
Sinisa VukCommented:
I build simple test with this lines:

1. after file is open in mediaplayer - get max value for trackbar:
TrackBar1.Max := Mediaplayer1.TrackLength[0];

Open in new window


2. in timer ...get current position:
  if Mediaplayer1.Mode in [mpPlaying, mpSeeking, mpPaused, mpOpen, mpStopped] then
  begin
    //Progress Bar to check if the track is playing
    if TrackBar1.Max<>0 then
    Begin
      TrackBar1.Tag := 1; //block re-enter in trackbar change evnt
      TrackBar1.Position := Mediaplayer1.Position;
      TrackBar1.Tag := 0;
    end;
  end;

Open in new window


3. on trackbar change event (with mouse):
var
  bPlaying: Boolean;
begin
  if TrackBar1.Tag>0 then Exit;
  if Mediaplayer1.Mode in [mpPlaying, mpSeeking, mpPaused, mpOpen, mpStopped] then
  begin
    bPlaying := (Mediaplayer1.Mode in [mpPlaying]);
    Mediaplayer1.Pause;
    Mediaplayer1.Position := TrackBar1.Position;
    if bPlaying then Mediaplayer1.Play;

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Sinisa VukCommented:
with progressbar - use on mouse down event:
ProgressBar1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Curr_pos: Integer;
begin
    Curr_pos := muldiv(Mediaplayer1.TrackLength[0], X, ProgressBar1.ClientWidth);

    //set to mediaplayer similar to upper example using trackbar
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
or override the "click" protected method
The click happens ... but the property is not published

type
  TProgressbar = class(Vcl.ComCtrls.TProgressbar)
  protected
    procedure Click; override;
  end;

  TForm1 = class(TForm)
    ProgressBar1: TProgressBar;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TProgressbar }

procedure TProgressbar.Click;
var P: TPoint;
begin
  P := ScreenToClient(Mouse.CursorPos);
  Position := Round(P.X/ Width*(Max - Min));
end;

Open in new window


then read the position to set the mediaplayer tracker
0
hidrauAuthor Commented:
Thanks for your example Sinsav, it is a good trick.

Geert Gruwez, could I do the same for Gauge?  Because sometimes I have a gauge and other progressbar.
0
hidrauAuthor Commented:
I forget to say, I use a component named AlphaControls and this component has the event onclick.
0
hidrauAuthor Commented:
thanks very much for both of you.
0
Geert GOracle dbaCommented:
works just in the same way
both ProgressBar and Gauge descend from TControl which has the click method in protected area
> basically you can do this with any control descending from TControl

  TGauge = class(Vcl.Samples.Gauges.Tgauge)
  protected
    procedure Click; override;
  end;

  { TGauge }

procedure TGauge.Click;
var P: TPoint;
begin
  P := ScreenToClient(Mouse.CursorPos);
  Progress :=  Round(P.X / Width * (MaxValue - MinValue));
end;

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.