Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Changing Position of Current Played Track in TMediaPlayer Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
02-Jun-03
Category
Multimedia
Language
Delphi 3.x
Views
181
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: h4ry p

Difficulties in moving forward/backward (changing position) the current played 
track in TMediaPlayer ??

Answer:

To change the current position of current playing track, you just need to take the 
usefull (advance) of two event: 1) onTimer of TTimer and 2) onChange of TScrollbar. 
For full code, read below. 

Here are the codes: 

1   procedure TForm1.Button1Click(Sender: TObject);
2   begin
3     if (OpenDialog1.Execute) then
4     begin
5       Timer1.Enabled := false;
6       MediaPlayer1.FileName := OpenDialog1.FileName;
7       MediaPlayer1.Open;
8       ScrollBar1.Max := MediaPlayer1.Length;
9       ScrollBar1.Position := 0;
10      Timer1.Enabled := true;
11    end;
12  end;
13  
14  procedure TForm1.Timer1Timer(Sender: TObject);
15  begin
16    ScrollBar1.OnChange := nil; // disable the event handler
17    ScrollBar1.Position := MediaPlayer1.Position;
18    ScrollBar1.OnChange := ScrollBar1Change; // enable it again
19  end;
20  
21  procedure TForm1.ScrollBar1Change(Sender: TObject);
22  begin
23    MediaPlayer1.Pause;
24    MediaPlayer1.Position := ScrollBar1.Position;
25    MediaPlayer1.Play;
26  end;


First thing you must do here is initiate the MAX range of TScrollBar with the 
length of the current song track (look at Button1Click above). 

Then add onTimer event code like above, and so the onChange event of TScrollBar. 
The key is you must set TMediaPlayer's position with your selected scroolbar position for each of onTimer happen. Do this by calling onChange event of TScrollBar in onTimer event of TTimer. 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC