type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
procedure mpNotify(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{$R test.res}
uses mmsystem, mplayer;
var
tmp: string;
mp: TMediaPlayer;
procedure TForm1.FormCreate(Sender: TObject);
var p: PChar;
tr: TResourcestream;
begin
getmem(p, max_path);
gettemppath(max_path, p);
GetTempFileName(p, 'x', 0, p);
tmp := changefileext(p, '.mp3');
freemem(p);
tr := tresourcestream.create(hinstance, 'musik', 'MP3');
tr.savetofile(tmp);
tr.free;
deletefile(changefileext(tmp, '.tmp'));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
deletefile(tmp);
end;
procedure TForm1.mpNotify(Sender: TObject);
begin
mp.free;
Button1.enabled := true;
end;
// Abspielen
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.enabled := false;
mp := TMediaPlayer.Create(nil);
with mp do begin
visible := false;
parent := Application.MainForm;
Shareable := true;
DeviceType := dtAutoSelect;
onNotify := mpNotify;
FileName := tmp;
open;
play;
end;
end;