perkley
asked on
I need CD Track Length and capability to use a track bar for position of song?
I have searched the Internet and tried a lot of different things, but I can't seem to find out how to get and use the Track Length of a .cda (CD File).
I am using TMediaPlayer to play the file.
I have tried getting the MediaPlayer1.TrackLength[8 ] or whatever, but it gives a huge number, and I was not able to convert it into a time format for me to use it in moving the track bar and having that particular song move forward. Any help would be greatly appreciated.
In order for me to accept your answer, I will need a solid answer in Delphi on how to get the track length and use it in a trackbar. Thanks.
I am using TMediaPlayer to play the file.
I have tried getting the MediaPlayer1.TrackLength[8
In order for me to accept your answer, I will need a solid answer in Delphi on how to get the track length and use it in a trackbar. Thanks.
ASKER
I understand what you have written and it works a little, but the problem is that when you move the trackbar then it can move to any track. I want to just move the position between that specific track that is playing.
Maybe it works for you, but it still does not seem to be working here.
I have used this before, just so you know.
mci_Make_TMSF
It works very well, except that I cannot get the trackbar to work with it.
Any more ideas.
Maybe it works for you, but it still does not seem to be working here.
I have used this before, just so you know.
mci_Make_TMSF
It works very well, except that I cannot get the trackbar to work with it.
Any more ideas.
// get the tracklen of the track
Len_m:=MCI_MSF_Minute(Medi aplayer.Tr ackLength[ TrackNo]);
Len_s:=MCI_MSF_Second(Medi aplayer.Tr ackLength[ TrackNo]);
Len_f:=MCI_MSF_Frame(Media player.Tra ckLength[T rackNo]);
Len_m:=MCI_MSF_Minute(Medi
Len_s:=MCI_MSF_Second(Medi
Len_f:=MCI_MSF_Frame(Media
ASKER
Yes, that does help me a little better, but how can I use that in a trackbar. My question specifically stated that I will not accept an answer until they explain both of those items. I want the length, and how to use it with a trackbar.
I need to know how to set the following:
MediaPlayer.Max
MediaPlayer.Position
On some TimerEvent
Show MediaPlayer.Position according to where CD is in the position of it's track in TrackBar.Position.
When TrackBar is moved then it sets new Position on the MediaPlayer for the just that track.
I hope that is a clear question of what I want, if not, leave a comment.
I need to know how to set the following:
MediaPlayer.Max
MediaPlayer.Position
On some TimerEvent
Show MediaPlayer.Position according to where CD is in the position of it's track in TrackBar.Position.
When TrackBar is moved then it sets new Position on the MediaPlayer for the just that track.
I hope that is a clear question of what I want, if not, leave a comment.
Setting the MediaPlayer position is pretty easy, just use this
MediaPlayer1.Position := mci_Make_TMSF(t, m, s, 0);
MediaPlayer1.Play;
You have to restart the playback after you've set the position as it does stop automatically.
To get the trackbar to update as the track is playing, add a TTimer and insert the following into the Timer event
t := MCI_TMSF_Track(Mediaplayer 1.Position );
m := MCI_TMSF_Minute(Mediaplaye r1.Positio n);
s := MCI_TMSF_Second(Mediaplaye r1.Positio n);
TrackBar1.Position := m * 60 + s;
Make sure that you set the time format to tfTMSF.
The problem comes in when you try to change the position of the track according to the position of the TrackBar. If you tie the setting code in with the OnChange event of the TrackBar you'll set the track position everytime the TrackBar updates BUT it's doing this everytime the timer fires, and you'll get a very sporadic playback. I never used a TrackBar in my player so I can't help you any further with that but you might be able to do something with boolean flags to disable updates when the user drags the bar
The Neil
MediaPlayer1.Position := mci_Make_TMSF(t, m, s, 0);
MediaPlayer1.Play;
You have to restart the playback after you've set the position as it does stop automatically.
To get the trackbar to update as the track is playing, add a TTimer and insert the following into the Timer event
t := MCI_TMSF_Track(Mediaplayer
m := MCI_TMSF_Minute(Mediaplaye
s := MCI_TMSF_Second(Mediaplaye
TrackBar1.Position := m * 60 + s;
Make sure that you set the time format to tfTMSF.
The problem comes in when you try to change the position of the track according to the position of the TrackBar. If you tie the setting code in with the OnChange event of the TrackBar you'll set the track position everytime the TrackBar updates BUT it's doing this everytime the timer fires, and you'll get a very sporadic playback. I never used a TrackBar in my player so I can't help you any further with that but you might be able to do something with boolean flags to disable updates when the user drags the bar
The Neil
ASKER
For those interested, this is what I ended up doing, and it works fine.
This code is running under the Timer.
I first set the TimeFormat like mentioned:
MediaPlayer.TimeFormat := tfTMSF;
I then Set the TrackBar.
TrackBar.Position := (MCI_TMSF_MINUTE(MediaPlay er.Positio n)*60)+
MCI_TMSF_SECOND(MediaPlaye r.Position );
And if you are interested, this is how I show the Elapsed Time or Time Left:
With MediaPlayer do begin
Min := MCI_TMSF_MINUTE(Position);
Sec := MCI_TMSF_SECOND(Position);
if varTime = 'Elapsed' then begin
//Show Time Elapsed
time_elap := (min * 60) + sec;
time_elap := BarSeekHorz.MaxValue - time_elap;
varRem := '-'+Format('%.2d:%.2d', [(Time_Elap div 60), (time_elap-60*(Time_Elap div 60))]);
TimeCode.Caption := VarRem;
end else
Timecode.Caption := Format('%.2d:%.2d', [Min, Sec]);
end;
These were the variables that I had set:
var
Min, Sec: Word;
Time_Elap, trk: Integer;
When I move the TrackBar Position, then I have an additional Event created called: OnStopTracking - Basically after I have let go of the mouse on the tracking.
CDPlayer.Pause;
CDPlayer.TimeFormat := tfTMSF;
CDPlayer.Position := mci_Make_TMSF(trk, (TrackBar.Position div 60), (TrackBar.Position mod 60),0);
CDPlayer.Play;
In order to setup the TrackBar correctly, I did the following:
TrackBar.Max := (MCI_MSF_Minute(MediaPlaye r.TrackLen gth[trk]*6 0)+
MCI_MSF_Second(MediaPlayer .TrackLeng th[trk]);
I want to thank both TheNeil and KangXY for their help. They at least guided me in the correct direction. This makes it very difficult, as I don't know who's answer to accept as the correct answer.
This code is running under the Timer.
I first set the TimeFormat like mentioned:
MediaPlayer.TimeFormat := tfTMSF;
I then Set the TrackBar.
TrackBar.Position := (MCI_TMSF_MINUTE(MediaPlay
MCI_TMSF_SECOND(MediaPlaye
And if you are interested, this is how I show the Elapsed Time or Time Left:
With MediaPlayer do begin
Min := MCI_TMSF_MINUTE(Position);
Sec := MCI_TMSF_SECOND(Position);
if varTime = 'Elapsed' then begin
//Show Time Elapsed
time_elap := (min * 60) + sec;
time_elap := BarSeekHorz.MaxValue - time_elap;
varRem := '-'+Format('%.2d:%.2d', [(Time_Elap div 60), (time_elap-60*(Time_Elap div 60))]);
TimeCode.Caption := VarRem;
end else
Timecode.Caption := Format('%.2d:%.2d', [Min, Sec]);
end;
These were the variables that I had set:
var
Min, Sec: Word;
Time_Elap, trk: Integer;
When I move the TrackBar Position, then I have an additional Event created called: OnStopTracking - Basically after I have let go of the mouse on the tracking.
CDPlayer.Pause;
CDPlayer.TimeFormat := tfTMSF;
CDPlayer.Position := mci_Make_TMSF(trk, (TrackBar.Position div 60), (TrackBar.Position mod 60),0);
CDPlayer.Play;
In order to setup the TrackBar correctly, I did the following:
TrackBar.Max := (MCI_MSF_Minute(MediaPlaye
MCI_MSF_Second(MediaPlayer
I want to thank both TheNeil and KangXY for their help. They at least guided me in the correct direction. This makes it very difficult, as I don't know who's answer to accept as the correct answer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
first, sorry for my poor english:)
OK, you'll accept TheNeil's anser,my anser too simple ,so I'll give up :)
OK, you'll accept TheNeil's anser,my anser too simple ,so I'll give up :)
ASKER
I accept the answer as average, since you pointed me in the right direction, but didn't show me how to implement it. But because I figured it out, the question is closed.
MediaPlayer1.TimeFormat := tfMilliseconds;
You can now get the track lengths and positions by using the TrackLength and TrackPos properties.
Assigning the values to a Trackbar is easy enough but you have to remember that you're working with milliseconds so ny value will be pretty big. Best way to handle this is to convert it to seconds
Trackbar1.Max := MediaPlayer1.TrackLength[1
Then to jump to a position specified by the trackbar, just reverse the process
MediaPlayer1.Position := TrackBar1.Position * 1000;
If you need any more then just ask
The Neil