Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Trackbar with MediaPlayer to change track position 1

Status
Not open for further replies.

doctorjellybean

Programmer
May 5, 2003
145
I've done a fair bit of googling, and I can't seem to find the solution.

I want to use the trackbar component with the mediaplayer component, and when I drag the trackbar to a selected position, mediaplayer updates the track and continue playing it from the selected position.

Hoping someone is wiser than me, thank you [smile]
 
If you look in the demos I provided with your first question about TMediaPlayer, you'll see that I have the functionality already coded in there if you were to pause the track ("stop"). That should get you 7/8 of the way there.

The only other problem that I didn't solve when I made those demos (and wasn't in the mood to while I was making those, I was more concerned about showing how to handle the text) was the issue of touching the trackbar while it was playing. In the demo, if you were to remove the code disabling the track bar, it could do exactly as you ask but you have to fight it updating itself as the music played.

If I had to guess at the moment, I would try first disabling Trackbar1.OnChange on click and then re-enabling it on release. If I have the time to, I can look into seeing how that is done.

----------
Measurement is not management.
 
Code:
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  MediaPlayer1.Position := TrackBar1.Position;
  MediaPlayer1.Play;
  LyricPos := 1;
  while LyricRecord[LyricPos].Offset < MediaPlayer1.Position do
    inc(LyricPos);
end;

Moving the trackbar changed the value and stopped the playback at that point. Just adding Play seems to make it work - it screeches a little bit at times but the playback continues from that position.

----------
Measurement is not management.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top