Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

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
0
hidrau
Asked:
hidrau
  • 4
  • 3
  • 2
2 Solutions
 
Geert GruwezOracle 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
Geert GruwezOracle 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 GruwezOracle 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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now