unit pl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
//Playlist-Tabelle
type
Tplaylist =
record
title:
string;
length: integer;
datei:
string;
end;
//Auslesen des ID3 Tags-Tabelle
Type
TID3Tag =
record
ID:
string[3];
Titel:
string[30];
Artist:
string[30];
Album:
string[30];
Year:
string[4];
Comment:
string[30];
Genre: byte;
dauer: longint;
//in sekunden;
sample: integer;
bits: byte;
vers: byte;
layers: byte;
end;
type
TForm3 =
class(TForm)
playlist: TListBox;
Add: TButton;
Button1: TButton;
Button2: TButton;
MainMenu1: TMainMenu;
Neu1: TMenuItem;
Play1: TMenuItem;
Playlist1: TMenuItem;
Lschen1: TMenuItem;
ffnen1: TMenuItem;
Speichern1: TMenuItem;
Suchennach1: TMenuItem;
Artist1: TMenuItem;
itle1: TMenuItem;
Album1: TMenuItem;
procedure itle1Click(Sender: TObject);
procedure ffnen1Click(Sender: TObject);
procedure Lschen1Click(Sender: TObject);
procedure Play1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure playlistKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure AddClick(Sender: TObject);
procedure playlistDblClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
const
MPEG_BIT_RATES :
array[1..3]
of array[1..3]
of array[0..15]
of word =
{ Version 1, Layer I }
(((0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0),
{ Version 1, Layer II }
(0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0),
{ Version 1, Layer III }
(0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0)),
{ Version 2, Layer I }
((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0),
{ Version 2, Layer II }
(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0),
{ Version 2, Layer III }
(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)),
{ Version 2.5, Layer I }
((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0),
{ Version 2.5, Layer II }
(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0),
{ Version 2.5, Layer III }
(0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)));
sample_rates:
array[1..3]
of array [0..3]
of word=
((44100,48000,32000,0),
(22050,24000,16000,0),
(11025,12000,8000,0));
var
Form3: TForm3;
pos, noft, tpassd: Integer;
//Trackposition, Azahl der Tracks, Vergangene Zeit des Aktuellen Tracks
list:
array of Tplaylist;
//deklarieren der oben vereinbarten Tabelle für die Playlist
//list hat immer den gleichen Index wie die Listbox playlist
ID3Tag: TID3Tag;
m3u: TStringlist;
implementation
uses maplayer, suchen;
{$R *.dfm}
//-------------------------------------//
procedure Lese_ID3Tag(Filename:
string);
var
Buffer:
array[1..128]
of char;
F:
File;
mp3hdrread:
array[1..4]
of byte;
mp3hdr: longint
absolute mp3hdrread;
tempbyte, bitrateindex, versionindex: byte;
bitrate, version, layer, groese: longint;
begin
AssignFile(F, Filename);
Reset(F,1);
groese:=filesize(f);
blockread(f,mp3hdrread,4);
tempbyte:=mp3hdrread[1];
mp3hdrread[1]:=mp3hdrread[4];
mp3hdrread[4]:=tempbyte;
tempbyte:=mp3hdrread[2];
mp3hdrread[2]:=mp3hdrread[3];
mp3hdrread[3]:=tempbyte;
reset(f,1);
Seek(F,FileSize(F)-128);
BlockRead(F, Buffer, SizeOf(Buffer));
CloseFile(F);
bitrateindex:=((mp3hdr
shr 12)
and $F);
versionindex:=((mp3hdr
shr 19)
and $3);
case versionindex
of
0: version:=3;
1: version:=0;
//unbekannt
2: version:=2;
3: version:=1;
end;
layer:=4-((mp3hdr
shr 17)
and $3);
if version<>0
then
bitrate:=MPEG_BIT_RATES[version][layer][bitrateindex]
else
bitrate:=128;
with ID3Tag
do
begin
ID:=copy(Buffer,1,3);
Titel:=copy(Buffer,4,30);
Artist:=copy(Buffer,34,30);
Album:=copy(Buffer,64,30);
Year:=copy(Buffer,94,4);
Comment:=copy(Buffer,98,30);
Genre:=ord(Buffer[128]);
sample:=sample_rates[version][((mp3hdr
shr 10)
and $3)];
dauer:=(groese*8)
div ((bitrate)*1000);
bits:=bitrate;
vers:=version;
layers:=layer;
end;
end;
//------------------------------------------------//
// Zum Abspielen des doppelt angeklickten Tracks // Funktioniert //
procedure TForm3.playlistDblClick(Sender: TObject);
begin
form1.timer2.Enabled := false;
form1.title.Caption := list[playlist.itemindex].Title;
form1.mediaplayer1.FileName := list[playlist.itemindex].datei;
pos := playlist.ItemIndex;
form1.mediaplayer1.Open;
form1.timer1.Interval := form1.mediaplayer1.TrackLength[0];
form1.timer1.Enabled := true;
tpassd := 0;
form1.left.Caption := inttostr(form1.mediaplayer1.tracklength[pos]
div 1000);
form1.position.Max := form1.mediaplayer1.TrackLength[0];
form1.position.Position := 0;
form1.timer2.Enabled := true;
form1.Mediaplayer1.Play;
form1.length.caption := inttostr((form1.mediaplayer1.tracklength[pos]
div 1000)
div 60)+ '
: ' + inttostr((form1.mediaplayer1.TrackLength[pos]
div 1000)
mod 60);
end;
//______Hinzufügen von einzelnen MP3´s________//
procedure TForm3.AddClick(Sender: TObject);
var i: Integer;
datei:
String;
begin
if form1.openmp3.Execute
then
begin
SetLength(list, 100000);
for i := 0
to form1.openmp3.Files.Count - 1
do
begin
datei := form1.openmp3.Files[i];
Lese_ID3Tag(datei);
list[i+noft].title := ID3Tag.Titel;
list[i+noft].length := ID3Tag.dauer;
list[i+noft].datei := datei;
if not (list[i+noft].title = '
')
then
playlist.Items.add (list[i+noft].title)
else
playlist.Items.add(form1.openmp3.filename);
end;
end;
noft := playlist.items.count;
end;
//Laden einer m3u Playlist
procedure TForm3.Button1Click(Sender: TObject);
var i,e, position: Integer;
datei :
String;
begin
playlist.Clear;
noft := 0;
SetLength(list, 100000);
m3u := TStringlist.Create;
if form1.m3uopen.Execute
then
begin
m3u.LoadFromFile(form1.m3uopen.filename);
if m3u.Strings[0] = '
#EXTM3U'
then
begin
e := 0;
for i := 0
to m3u.Count - 1
do
begin
position := ansipos ('
#' , m3u.Strings[i]);
if not (position = 1)
then
begin
try
datei := m3u.Strings[i];
Lese_ID3Tag(datei);
list[e].title := ID3Tag.Titel;
list[e].length := ID3Tag.dauer;
list[e].datei := datei;
playlist.Items.add (list[e].title);
except
datei := m3u.Strings[e];
playlist.Items.add (datei);
end;
e := e+1;
end;
end;
noft := playlist.items.count;
form3.Caption := form1.m3uopen.FileName;
end
else
showmessage ('
Keine gültige m3u-Playlist!');
end;
end;
//Aufrufen der Suchfunktion
procedure TForm3.Button2Click(Sender: TObject);
begin
form2.showmodal;
end;
procedure TForm3.playlistKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (Key = ord('
S') )
then
form2.showmodal;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
form3.Left := 0;
form3.Top := form1.Top + form1.Height + 10;
end;
procedure TForm3.Play1Click(Sender: TObject);
begin
add.Click;
end;
procedure TForm3.Lschen1Click(Sender: TObject);
begin
playlist.Clear;
pos := 0;
noft := 0;
end;
procedure TForm3.ffnen1Click(Sender: TObject);
begin
button1.Click;
end;
procedure TForm3.itle1Click(Sender: TObject);
begin
form2.ShowModal;
end;
end.