type
TID3Tag =
record
ID :
string[3];
Titel :
string[30];
Artist :
string[30];
Album :
string[30];
Year :
string[4];
Comment :
string[30];
Genre : Byte;
FileName :
string;
end;
//...
private
fFiles :
Array of TID3Tag;
//...
function TfrmMain.GetBASSInfo(Info:
String): Int64;
var
MilliSec: Integer;
FloatPos: Float;
begin
FloatPos:=0;
if Info = '
GetLength'
then FloatPos:=BASS_ChannelBytes2Seconds(Chan, BASS_ChannelGetLength(Chan))
else if Info = '
GetPosition'
then FloatPos:=BASS_ChannelBytes2Seconds(Chan,
BASS_ChannelGetPosition(Chan));
MilliSec := Trunc(1000 * FloatPos);
if MilliSec < 0
then MilliSec:=0;
Result := Trunc(MilliSec / 1000);
end;
procedure TfrmMain.PlayFile(
index : integer);
var filename :
String;
begin
if (
index < 0)
or (
index >= length(fFiles))
then
begin
raise Exception.Create('
Index ausserhalb des erlaubten bereichs');
end;
BASS_ChannelSetPosition(chan, 0);
BASS_ChannelStop(chan);
filename := fFiles[
index].FileName;
chan := BASS_StreamCreateFile(FALSE,pchar(filename),0,0,0);
if chan = 0
then
begin
chan := BASS_MusicLoad(False, pchar(filename), 0, 0, BASS_MUSIC_RAMPS
or BASS_MUSIC_POSRESET
or BASS_MUSIC_PRESCAN, 0);
if (chan = 0)
then
begin
ErrorPop('
Kann das Lied nicht abspielen !');
Exit;
end;
end;
tb1.Position := 0;
tb1.Max := GetBASSInfo('
GetLength');
end;
procedure TfrmMain.ErrorPop(str:
string);
begin
if str = '
'
then
Showmessage('
Error code: '+inttostr(BASS_ErrorGetCode()))
else
Showmessage(str);
end;
//...
var playiindex : Integer;
begin
// tb1 = XiTrackbar (vom programmieren aus gesehen, genauso wie eine normale TTrackBar)
// lbList = ListBox
playindex := Max(0, (lbList.ItemIndex + 1)
mod lbList.Items.Count);
if playindex = lbList.Items.Count
then
playindex := 0;
tb1.Max := GetBASSInfo('
GetLength');
PlayFile(playindex);
end;