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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ok I'm a Delphi newbie and I need some help with a mp3player

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
ok I know the world has enough MP3 players as it is but I'm just messing around a bit. I'm a PASCAL programmer but I've never done object oriented programming.

so I've started to build a simple MP3 player with a playlist. everything works just fine but now I want a nice little bar that show the progress of the MP3-track and I want to use that bar to skip through the song.

my question: is there a simple way to solve this? I'm using the MediaPlayer object.

thanx in advance!
JohnD
 
This is a very rough (and buggy) solution to your problem. I post it only that I hope it will help you somehow.

OK...Drop a Timer (System tab) and a TrackBar (Win32).
Set the following properties to TrackBar1: FileName->'Roxette.MP3' (the media file you want to be played), Max->100 (think of it as percents of the song - you can adapt it), PageSize->1 (the amount of lines the thumb of the trackbar skips when you click it), ThumbLength->12 (adjust this as you like). Now, some code:

//put this in OnTimer event of the Timer1 control...
procedure TForm1.Timer1Timer(Sender: TObject);
begin
trackbar1.Position:=round(mediaplayer1.Position*
100/mediaplayer1.Length);
end;

//and this in OnChange event of the TrackBar1
procedure TForm1.TrackBar1Change(Sender: TObject);
var k:longint;
begin
k:=round(mediaplayer1.Length/100);
mediaplayer1.Position:=trackbar1.Position*k;
mediaplayer1.Play;
end;

The only problem is that the trackbar's OnChange event should be called only when it's clicked. But the trackbar doesn't have any mouse-related events, so I don't know what to do with this. If you remove the second procedure (so that the trackbar acts only as ProgressBar), it works just fine), but you won't be able to skip within the song.
That's it... Raz (just trying to be useful)
 
ok thank you very much for your reply sir but that was an old thread and I already found a solution.

timer procedure:
===================================================
procedure TForm1.Timer1Timer(Sender: TObject);
begin
TrackBar1.Max := MediaPlayer1.Length;
TrackBar1.Min := 0;
TrackBar1.Position:=MediaPlayer1.Position;;
if TrackBar1.Position = TrackBar1.Max then
begin
timer1.Enabled := false;
MediaPlayer1.stop;
MediaPlayer1.rewind;
TrackBar1.Position := MediaPlayer1.Position;
MediaPlayer1.EnabledButtons := [btPlay];
end;
end;
===================================================

if somebody changes the trackbar:
===================================================
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if MediaPlayer1.EnabledButtons = [btPause,btStop] then
begin
MediaPlayer1.Position:=TrackBar1.Position;
MediaPlayer1.Play;
end;
if MediaPlayer1.EnabledButtons = [btPlay,btStop] then
MediaPlayer1.Position:=TrackBar1.Position;
if MediaPlayer1.EnabledButtons = [btPlay] then
begin
TrackBar1.Max := MediaPlayer1.Length;
TrackBar1.Min := 0;
MediaPlayer1.Position:=TrackBar1.Position;
end;
end;
===================================================

X-)

 
OK, I'm glad you found a solution. I also found a solution to the problem my code posed, than I saw your post was a month old so I didn't expect my solving to be useful anymore. So I won't post it anymore.
Well, good luck...
Raz (just trying to be useful)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top