unit Query;
interface
uses
ComObj,
ComTool,
SysUtils,
Variants,
Windows,
iTunesLib_TLB;
implementation
function queryFile(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
ret : AnsiString;
track : IITTrack;
tkind : ITTrackKind;
ftrack : IITFileOrCDTrack;
utrack : IITURLTrack;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
tkind := track.Kind;
if tkind = ITTrackKindURL
then begin
utrack := IDispatch(iTunes.CurrentTrack)
as IITURLTrack;
ret := AnsiString(utrack.URL);
end
else begin
ftrack := track
as IITFileOrCDTrack;
ret := AnsiString(ftrack.Location);
end;
if (ret <> '
')
then begin
StrCopy(data, PAnsiChar(ret));
Exit(3);
end
end;
end;
except
end;
StrCopy(data, '
n/a');
Result := 3;
end;
function queryType(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
name, uret : AnsiString;
fret : PAnsiChar;
track : IITTrack;
tkind : ITTrackKind;
ftrack : IITFileOrCDTrack;
utrack : IITURLTrack;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
tkind := track.Kind;
if tkind = ITTrackKindURL
then begin
utrack := IDispatch(iTunes.CurrentTrack)
as IITURLTrack;
name := AnsiString(utrack.URL);
uret := Copy(
name, 1, Pos(AnsiString('
://'),
name) - 1);
StrCopy(data, PAnsiChar(uret));
Exit(3);
end
else if (tkind = ITTrackKindFile)
or (tkind = ITTrackKindCD)
then begin
ftrack := track
as IITFileOrCDTrack;
name := AnsiString(ftrack.Location);
fret := AnsiStrRScan(PAnsiChar(
name), '
.') + 1;
StrCopy(data, fret);
Exit(3);
end;
end;
end;
except
end;
StrCopy(data, '
n/a');
Result := 3;
end;
function queryTitle(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
name, interp : AnsiString;
track : IITTrack;
tkind : ITTrackKind;
ftrack : IITFileOrCDTrack;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
tkind := track.Kind;
if tkind = ITTrackKindURL
then begin
name := AnsiString(VarToStr(iTunes.CurrentStreamTitle));
StrCopy(data, PAnsiChar(
name));
Exit(3);
end
else if (tkind = ITTrackKindFile)
or (tkind = ITTrackKindCD)
then begin
ftrack := track
as IITFileOrCDTrack;
interp := AnsiString(ftrack.Artist);
name := AnsiString(ftrack.
name);
StrCopy(data, PAnsiChar(interp));
StrCat(data, '
- ');
StrCat(data, PAnsiChar(
name));
Exit(3);
end;
end;
end;
except
end;
StrCopy(data, '
n/a');
Result := 3;
end;
function queryBitrate(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
track : IITTrack;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
StrCopy(data, PAnsiChar(AnsiString(IntToStr(track.BitRate))));
Exit(3);
end;
end;
except
end;
StrCopy(data, '
-1');
Result := 3;
end;
function queryLength(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
track : IITTrack;
tkind : ITTrackKind;
ftrack : IITFileOrCDTrack;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
tkind := track.Kind;
if tkind = ITTrackKindURL
then begin
StrCopy(data, '
-1');
Exit(3);
end
else if (tkind = ITTrackKindFile)
or (tkind = ITTrackKindCD)
then begin
ftrack := track
as IITFileOrCDTrack;
StrCopy(data, PAnsiChar(AnsiString(IntToStr(ftrack.Duration))));
Exit(3);
end;
end;
end;
except
end;
StrCopy(data, '
-2');
Result := 3;
end;
function queryLengthF(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
track : IITTrack;
tkind : ITTrackKind;
ftrack : IITFileOrCDTrack;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
tkind := track.Kind;
if tkind = ITTrackKindURL
then begin
StrCopy(data, '
Stream');
Exit(3);
end
else if (tkind = ITTrackKindFile)
or (tkind = ITTrackKindCD)
then begin
ftrack := track
as IITFileOrCDTrack;
StrCopy(data, PAnsiChar(AnsiString(ftrack.Time)));
Exit(3);
end;
end;
end;
except
end;
StrCopy(data, '
n/a');
Result := 3;
end;
function queryPosition(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
StrCopy(data, PAnsiChar(AnsiString(IntToStr(iTunes.PlayerPosition))));
Exit(3);
end;
end;
except
end;
StrCopy(data, '
-2');
Result := 3;
end;
function queryPositionF(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing, b, m, s : integer;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
b := iTunes.PlayerPosition;
s := b
mod 60;
m := b
div 60;
StrCopy(data, PAnsiChar(AnsiString(Format('
%d:%02d', [m, s]))));
Exit(3);
end;
end;
except
end;
StrCopy(data, '
n/a');
Result := 3;
end;
function queryStatus(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
StrCopy(data, PAnsiChar(AnsiString(IntToStr(iTunes.PlayerState))));
Exit(3);
end;
except
end;
StrCopy(data, '
-1');
Result := 3;
end;
function queryStatusF(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
state : ITPlayerState;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
state := iTunes.PlayerState;
case state
of
ITPlayerStateStopped: StrCopy(data, '
Gestoppt');
ITPlayerStatePlaying: StrCopy(data, '
Laufend');
ITPlayerStateFastForward: StrCopy(data, '
Vorspulen');
ITPlayerStateRewind: StrCopy(data, '
Zurückspulen');
else StrCopy(data, '
Fehler');
end;
Exit(3);
end;
except
end;
StrCopy(data, '
-1');
Result := 3;
end;
function queryNum(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
playlist : IITPlaylist;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
playlist := IDispatch(iTunes.CurrentPlaylist)
as IITPlaylist;
StrCopy(data, PAnsiChar(AnsiString(IntToStr(playlist.Tracks.Count))));
Exit(3);
end;
end;
except
end;
StrCopy(data, '
-2');
Result := 3;
end;
function queryInfo(mWnd, aWnd: HWND; data, parms: PAnsiChar; show, nopause:boolean) : integer;
stdcall;
var
iTunes : OleVariant;
playing : integer;
track : IITTrack;
tkind : ITTrackKind;
begin
try
iTunes := CreateOleObject('
iTunes.Application');
if not VarIsNull(iTunes)
then begin
playing := iTunes.PlayerState;
if playing > 0
then begin
track := IDispatch(iTunes.CurrentTrack)
as IITTrack;
tkind := track.Kind;
if tkind = ITTrackKindURL
then begin
StrCopy(data, '
2');
Exit(3);
end
else if (tkind = ITTrackKindFile)
or (tkind = ITTrackKindCD)
then begin
StrCopy(data, '
1');
Exit(3);
end
else begin
StrCopy(data, '
3');
Exit(3);
end;
end;
end
else begin
StrCopy(data, '
0');
Exit(3);
end;
except
end;
StrCopy(data, '
-1');
Result := 3;
end;
exports
queryFile,
queryType,
queryTitle,
queryBitrate,
queryLength,
queryLengthF,
queryPosition,
queryPositionF,
queryStatus,
queryStatusF,
queryNum,
queryInfo;
end.