Note that this Wiki is a work in progress, items may not be updated or may disappear entirely as the pages are updated.
PAL: General Overlay rotation
From SpacialAudio
Question:
I need to make inventory available for 1-to-1 targeting. What is an easy way to regularly pick a tagged content item from my media library to add to the queue?
Answer:
The PAL script below will select a tagged (i.e. overlay=yes) track from the media library which has not played in the longest time every 20 minutes.
{*
Description:
This PAL script can be configured to trigger ad-space for 1-to-1 targeting
by scheduling content with "overlay=yes" into the queue
a) Every xx minutes, or
b) Every xx songs that play
This is done by editing the "WaitMinutes" and "WaitSongs" constants below.
Please note ONE of these values must be zero as you generally do not want to wait
xx minutes AND xx songs before playing advertisements.
This script will only insert one item at a time.
Recommended values:
WaitMinutes = 20;
WaitSongs = 0;
*}
//==============================================================================
// Custom settings - Please change these as required
//==============================================================================
//NOTE: Only ONE of these needs to be set, the other one needs to be zero
const WaitMinutes = 20; //Play advertisements every xx minutes
const WaitSongs = 0; //Play advertisements every xx songs
//==============================================================================
var doWait : boolean;
var songCount : Integer = 0;
var songInfo : TSongInfo;
var Q : TDataSet;
if (WaitMinutes<>0) AND (WaitSongs<>0) then
begin
WriteLn('Warning: Set either WaitMinutes or WaitSongs, not BOTH!');
end;
//Insert overlay trigger content
Q := Query('SELECT filename FROM songlist WHERE overlay=:yes ORDER BY date_played ASC LIMIT 1',['yes'], true);
if not (Q.BOF and Q.EOF) then
begin
Q.First;
Queue.AddFile(Q['filename'],ipTop);
end;
//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;
