VOA Science For Schools.PAL

This one is designed to play the weekly VOA Science program at a specific time. VOA programs are recorded MP3 files, so they are easy to grab.


PAL.Loop := True;

var S            : TSongInfo;
var P1, P2       : TPlayer;
var A1, A2       : TPlayer;
var i            : integer;
var N            : Integer;
var Filename     : String;
var Title        : String;
var y,m,d,hh,mm,ss,ms,SThh,STmm,STss,STms,QThh,QTmm,QTss,QTms : Integer;
var DC : Integer = 1;               //Day Count
var CC,DoWn : Float;
var DD,DT : DateTime;
var TT : Integer;          // dummy counter

P1 := DeckA;
P2 := DeckB;
A1 := Aux1;
A2 := Aux2;

// ******************  Configuration Options  *******************
var VOAProgram : String = 'http://www.quantum-radio.uk/audio_files/mp3/science_for_schools/BPPBPodcast1.mp3';
var ProgramTitle : String = 'Science for Schools';
var QueueAtTime : DateTime = (T['14:30:00']);  // 7 days from now. It only plays once a week remember
var StartTodayAt : DateTime = (T['14:30:00']);  // Starting at the right time on the right day.
var PlayDay : Integer = 2; // Sunday-1, Monday-2, Tuesday-3 Wednesday-4 Thursday-5 Friday-6 Saturday-7
// ******************  End of Configuration Options  *******************

{
  Logic. If play time is later this week than when the script starts,
             then it sets QueueAtTime to that day.
         If it's actually today, and not yet time, then it sets
             QueueAtTime to todays time. If the time today has already passed,
             then it sets play start time to the correct time to play next week.
         If none of that seems logical, then it just sets the PlayTime to the
             correct time next week.

}

         DoWn := DayOfWeek(Now);
         if (PlayDay > DoWn) then
            CC := (7-DoWn)
            else if (PlayDay = DoWn) and (StartTodayAt>DateTime(Now)) then
            CC := 0
            else
            CC := (7-DoWn)+PlayDay;

         QueueAtTime := QueueAtTime+CC;

         WriteLn(QueueAtTime);
         PAL.WaitForTime(QueueAtTime);


// ------- Set up the AUX players to play the time files ---------
    A1.Volume := 255; // and play it LOUD
    A2.Volume := 255; // and play it LOUD

//OK, I'm going to use Aux2.... because it's there...

// Just in case something is in Aux2, hang about till it's gone
         repeat
          N := N+1;
          until (A2.Status = psReady);
          N := 0;
  Filename := VOAProgram;
  WriteLn(VOAProgram);
  Title := ProgramTitle;
  WriteLn(ProgramTitle);
    S := TSongInfo.Create;
    S['filename'] := Filename;
     S['title'] := Title;
        ActivePlayer.FadeToPause;

         A2.QueueSong(S);
         A2.Play;
         repeat
          N := N+1;
          until (A2.Status = psReady);
          S.Free;

        if (DeckA.Status = psQueued) then
           P1.FadeToPlay
           else if (DeckB.Status = psQueued) then
           P2.FadeToPlay;
           
           PAL.WaitForTime('00:00:02');     // Settle for two seconds
 // ---------------------- End of AUX player setup ---------
// Reset Volume Back To Normal just in case "someone" has messed them up!
A1.Volume := 255;
A2.Volume := 255;
P1.Volume := 255;
P2.Volume := 255;

// ok, now wait until 2:30pm next Tuesday
PAL.WaitForTime(QueueAtTime); {## 7 Days from now}