unit playlist;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, StdCtrls, Buttons, ExtCtrls;
type
TInfos =
class
Filename:
string;
public
property Str:
string read Filename
write Filename;
end;
type
TTracks =
record
Title:
String;
time:
String;
path:
String;
no: Integer;
end;
type
TPlayList =
class(TStringGrid)
private
function GetTracks(
index:integer):TTracks;
{ Private-Deklarationen }
protected
{ Protected-Deklarationen }
public
constructor Create (AOwner: TComponent);
override;
Procedure KeyDown(
var Key: Word; Shift: TShiftState);
override;
{ Public-Deklarationen }
published
procedure DeleteRow (RowNumber : Integer);
procedure addFile (pfad, dauer, titel:
String);
procedure openM3u (m3u:
String);
procedure savem3u (m3u:
String);
property Track[
index:integer]:TTracks
read GetTracks;
{ Published-Deklarationen }
end;
procedure Register;
implementation
constructor TPlaylist.Create(AOwner: TComponent);
var option: TGridOptions;
begin
inherited Create (AOwner);
options := [gorowselect] + [gocolsizing]+ [gofixedvertline] + [gofixedhorzline] + [govertline] + [gohorzline];
rowcount := 2;
colcount := 3;
fixedcols := 0;
fixedrows := 1;
defaultrowheight := 15;
rowheights[0] := 18;
Cells[1,0] := '
Title';
Cells[2,0] := '
Length';
Cells[0,0] := '
No';
ColWidths[0] := 30;
colwidths[1] := 200;
colwidths[2] := 50;
end;
function TPlaylist.GetTracks (
index: Integer): TTracks;
begin
Result.no := strtoint(cells[0,
index]);
Result.Title:= cells[1,
index];
Result.time := cells[2,
index];
Result.path := cells[3,
index];
end;
procedure TPlaylist.savem3u(m3u:
String);
var i: Integer;
list: TStringlist;
begin
list := TStringlist.Create;
list.Add('
#EXTM3U');
for i := 1
to rowcount-1
do
begin
list.Add('
#EXTINF:'+cells[2,i]+'
,'+ cells[1,i]);
list.Add(cells[3,i]);
end;
list.SaveToFile(m3u);
list.Free;
end;
procedure TPlaylist.openM3u (m3u:
String);
var i, position: Integer;
list: Tstringlist;
path, time, title:
String;
begin
list := TStringlist.Create;
list.LoadFromFile(m3u);
if list.Strings[0] = '
#EXTM3U'
then
begin
for i := 0
to list.Count - 1
do
begin
position := ansipos ('
#EXTINF:' , list.Strings[i]);
if position = 1
then
begin
time := copy(list.strings[i],9,3);
title := copy(list.strings[i],13,1000);
path := list.Strings[i+1];
addfile(path,time,title);
end;
end;
end;
end;
procedure TPlaylist.addFile (pfad, dauer, titel:
String);
var i: Integer;
mo: TInfos;
begin
rowcount := rowcount + 1;
mo:=TInfos.create;
mo.Filename:='
';
Objects[rowcount-2,3]:=mo;
cells[1, rowcount-2] := titel;
cells[2, rowcount-2] := dauer;
cells[0,rowcount-2] := inttostr(rowcount - 2);
cells[3,rowcount-2] := pfad;
end;
procedure Tplaylist.DeleteRow(RowNumber : Integer);
var
i : Integer;
begin
for i := RowNumber
to RowCount - 2
do
Rows[i].Assign(Rows[i+ 1]);
Rows[RowCount-1].Clear;
RowCount := RowCount - 1;
for i := 1
to rowcount
do
cells[0,i] := inttostr(i);
end;
procedure TPlaylist.KeyDown(
var Key: Word; Shift: TShiftState);
begin
if key = vk_delete
then
if (row <> 0)
then
deleterow(row);
end;
procedure Register;
begin
RegisterComponents('
Standard', [TPlayList]);
end;
end.