unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Mask, StdCtrls, ExtCtrls, Grids, MPlayer;
type
TAudiofile = record
path: String[255];
title, artist, album, genre: String[30];
year: String[4];
end;
TForm1 = class(TForm)
MediaPlayer: TMediaPlayer;
Button1: TButton;
OpenDialog: TOpenDialog;
ListBox: TListBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure save(filepath: String);
procedure loadalldata;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private-Deklarationen }
seeker: Integer;
RAudiofile: TAudiofile;
musicdata: file of TAudiofile;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
RAudiofile: TAudiofile;
implementation
uses medialibrary;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
assignfile(musicdata,'data.dat');
seeker := 0;
if fileexists('data.dat') then
begin
Reset(musicdata);
loadalldata;
if filesize(musicdata) <> 0 then
begin
seek(musicdata,seeker);
read(musicdata,RAudiofile);
mediaplayer.close;
mediaplayer.filename := RAudiofile.path;
mediaplayer.open;
mediaplayer.play;
end;
end
else
rewrite(musicdata);
end;
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
if opendialog.execute then
begin
for i := 0 to (opendialog.files.count -1) do
begin
save(opendialog.files[i]);
end;
end;
end;
procedure TForm1.save(filepath: String);
begin
with RAudiofile do
begin
path := filepath;
title := '';
artist :='';
album := '';
genre := '';
year := '';
end;
seeker := filesize(musicdata);
seek(musicdata, seeker);
write(musicdata, RAudiofile);
end;
procedure TForm1.loadalldata;
var i: Integer;
begin
for i := 0 to (filesize(musicdata) - 1) do
begin
seeker := i;
seek(musicdata, seeker);
read(musicdata, RAudiofile);
Form2.listbox1.items[i] := RAudiofile.path;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
closefile(musicdata);
end;
end.