Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
Delphi XE2 Architect
|
Re: Trackbar/Zeit
11. Dez 2004, 02:29
Code:
{--------------------------------- SongPos ----------------------------------}
procedure TAudioEngine.Set_SongPos(SongPos : Integer);
begin
if WriteToFile Then
Exit;
SongPos := BASS_ChannelSeconds2Bytes(Channel, SongPos / 1000);
BASS_ChannelSetPosition(Channel, trunc(SongPos));
end;
function TAudioEngine.Get_SongPos : Integer;
var SongPos : QWORD;
MilliSec : Integer;
FloatPos : FLOAT;
begin
SongPos := BASS_ChannelGetPosition(Channel);
FloatPos:= BASS_ChannelBytes2Seconds(Channel, SongPos);
MilliSec:= Trunc(1000 * FloatPos);
if MilliSec < 0 then
MilliSec:= 0;
if (PlayerState = ENGINE_STOP) or (PlayerState = ENGINE_SONG_END) then
Result := 0
else
Result := MilliSec;
end;
//
Code:
var Scroling : boolean;
procedure TMain_Form.Slider_TimerTimer(Sender: TObject);
var len : integer;
begin
with AudioPlayer do
begin
Len:= Get_SongLen;
if Len <= 0 then
begin
Slider.Position:= 0;
exit;
end;
if Scroling = false then // Slider
Slider.Position:= trunc((Slider.MaxValue / Len) * Get_SongPos + 0.1);
end;
end;
procedure TMain_Form.SliderMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Scroling:= true;
end;
procedure TMain_Form.SliderMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with AudioPlayer do
begin
Set_SongPos(Trunc(Get_SongLen * slider.Position / Slider.MaxValue + 0.1));
Scroling:= false;
end
end;
//
Die Plugin’s findest du bei http://www.un4seen.com/
Code:
function TAudioEngine.Get_SongLength(FileName : String): Integer;
var Chn : DWORD;
Res, MilliSec : Integer;
SongLength : QWORD;
FloatPos : FLOAT;
ext : string;
begin
Ext:= UpperCase(ExtractFileExt(FileName));
Chn := BASS_StreamCreateFile(FALSE, PChar(FileName), 0, 0, 0);
if (EXT = '.WMA') or
(EXT = '.WMV') or
(EXT = '.ASF') then
Chn:= BASS_WMA_StreamCreateFile(FALSE, PChar(FileName), 0, 0, 0);
if (EXT = '.FLAC') then
Chn:= BASS_FLAC_StreamCreateFile(FALSE, PChar(FileName), 0, 0, 0);
if (EXT = '.MP4') or (EXT = '.M4A') then
Chn:= BASS_MP4_StreamCreateFile(PChar(FileName), 0);
if (EXT = '.AAC') then
Chn:= BASS_AAC_StreamCreateFile(PChar(FileName), 0);
if (EXT = '.CDA') then
Chn:= BASS_CD_StreamCreateFile(PChar(FileName), 0);
if (EXT = '.APE') then
Chn:= BASS_APE_StreamCreateFile(PChar(FileName), 0);
if (EXT = '.MPC') then
Chn:= BASS_MPC_StreamCreateFile(PChar(FileName), 0);
if Chn <> 0 then
SongLength := BASS_StreamGetLength(Chn);
if (Chn = 0) then
begin
Chn := BASS_MusicLoad(FALSE, PChar(FileName), 0, 0, 0, 0);
SongLength := BASS_MusicGetLength(Chn, True);
end;
if (Chn <> 0) then
begin
FloatPos:= BASS_ChannelBytes2Seconds(Chn, SongLength);
MilliSec:= Trunc(1000 * FloatPos);
if MilliSec < 0 then
MilliSec:= 0;
Res:= MilliSec;
end
else
Res := -1;
BASS_StreamFree(Chn);
BASS_MusicFree(Chn);
result := res;
end;
var
function DurationMinSec(Secunden : string) : string;
var Min, Sec : integer;
SecToTime : string;
begin
Min:= StrToInt(Secunden) div 60;
Sec:= StrToInt(Secunden) - Min * 60;
SecToTime:= Format('%2d:%.2d', [Min, Sec]);
result:= SecToTime;
end;
var Time : integer;
Time:= trunc(Audioplayer.Get_SongLength(Files.Strings[i]) / 1000);
label1.Caption:= DurationMinSec(inttostr(Time)));
|
|
Zitat
|