// StreamAds Advertisement rotation script
//==============================================================================
// Custom settings - Please change these as required
//==============================================================================
const AdSpace = 90; //Advertisement space, in seconds
//NOTE: Only ONE of these needs to be set, the other one needs to be zero
const WaitMinutes = 1; //Play advertisements every xx minutes
const WaitSongs = 0; //Play advertisements every xx songs
//==============================================================================
var doWait : boolean;
var songCount : Integer = 0;
var songInfo : TSongInfo;
if (WaitMinutes<>0) AND (WaitSongs<>0) then
begin
WriteLn('Warning: Set either WaitMinutes or WaitSongs, not BOTH!');
end;
//Insert advertisements
StreamAds['Providers (All)'].QueueTop(AdSpace);
//Wait for first Ad to start playing
//This will avoid LONG shows (60+ minutes) causing this script to
//queue a bunch of ads every 20 minutes
PAL.WaitForPlayCount(1);
//If WaitMinutes is set, wait for specified minutes
doWait := WaitMinutes>0;
while (doWait) do
begin
WriteLn('Waiting for '+IntToStr(WaitMinutes)+' minutes:');
PAL.WaitForTime(DateTime(Now+(WaitMinutes/(60*24))));
doWait := false;
end;
//If WaitSongs is set, wait for specified number of tracks to play
//Note: We specifically do not count advertisements!
if (WaitSongs>0) then
begin
WriteLn('Waiting for '+IntToStr(WaitSongs)+' to play:');
WriteLn('Note: Advertisements are not counted');
end;
songCount := 0;
while (WaitSongs>songCount) do
begin
//Check that track is not advertisement
//Increase counter only if non-advertisement
if (ActivePlayer <> nil) then
begin
songInfo := ActivePlayer.GetSongInfo();
if(songInfo['songtype'] <> 'A') then
begin
songCount := songCount + 1;
WriteStr(songCount); WriteStr(' ');
end;
songInfo.Free;
end;
//Only wait if needed
doWait := true;
while (doWait) and (WaitSongs>songCount) do
begin
PAL.WaitForPlayCount(1);
doWait := false;
end;
end;
//One we are done, start from top again
PAL.Loop := true;