unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, iTunesLib_TLB, iTunesLibEvents, ExtCtrls, StdCtrls;
type
TfrmMain =
class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TrackChangedEvent(Sender: TObject; iTrack: OleVariant);
private
iTunesApp: IiTunes;
EventManager: TiTunesLibIiTunesEvents;
public
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
iTunesApp := COiTunesApp.Create;
EventManager := TiTunesLibIiTunesEvents.Create(Self);
EventManager.OnPlayerPlayingTrackChangedEvent := TrackChangedEvent;
EventManager.Connect(iTunesApp);
end;
procedure TfrmMain.TrackChangedEvent(Sender: TObject; iTrack: OleVariant);
var
Track: IITTrack;
begin
Assert(VarType(iTrack) = varDispatch);
Track := IDispatch(iTrack)
as IITTrack;
Label1.Caption := Track.Album;
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
EventManager.Disconnect;
FreeAndNil(EventManager);
// iTunesApp.Quit;
iTunesApp :=
nil;
end;
end.