Now Playing Notification Script Not Working

Actually …

… I’ve been thinking (uh-oh!) …

… and there is a reason to use a Notification Script instead of a log file to create your ‘now playing’ info., especially if you are a live assist station and not an automated one.

In an automated station, you will always have ‘something’ playing, but in a live assist station, you might not. Your presenter could be interviewing someone in the studio, for example. Using a log file would mean that your ‘now playing’ info. would always show the last track started, even if nothing is currently playing.

A better solution would be to check how many Players are currently running, and when the count reaches zero, post a ‘we are not playing anything’ file instead. I think Charlie Davy may have done something like this before, but my solution is below.

[code]// NowPlayingText.mls - Notification Script for mAirList

// Writes a text file with the currently playing song details.

// The script also keeps a count of the number of ‘running’ Players,
// and writes a ‘NOT playing’ file if NO players are playing.

// Author: Cad Delworth
// (based on the NowPlayingHTML.mls script by Dr. Torben Weibert)

var
iStartedPlayerCount: integer;

procedure OnPlayerStart(PlaylistIndex: integer; PlayerIndex: integer; Item: IPlaylistItem);
var
sl: TStringList;
begin
iStartedPlayerCount := iStartedPlayerCount + 1;
// SystemLog(‘NowPlayingText: Player started: count is ’ + IntToStr(iStartedPlayerCount));
sl := TStringList.Create;
try
sl.Add(’’);
sl.Add(‘Now Playing’);
sl.Add(’’);
sl.Add(‘

Artist: ’ + Item.GetArtistsString + ‘
Title: ’ + Item.GetTitle + ‘

’);
sl.Add(’’);
sl.Add(’’);
sl.SaveToFile(‘c:\NowPlaying.html’);
finally
sl.Free;
end;
end;

procedure OnPlayerStop(PlaylistIndex: integer; PlayerIndex: integer; Duration: TTimeValue; Item: IPlaylistItem);
var
sl: TStringList;
begin
iStartedPlayerCount := iStartedPlayerCount - 1;
if iStartedPlayerCount < 0 then
begin
SystemLog(‘NowPlayingText: Player count is negative! Resetting to zero.’);
iStartedPlayerCount := 0;
end;
// SystemLog(‘NowPlayingText: Player stopped: count is ’ + IntToStr(iStartedPlayerCount));
if iStartedPlayerCount = 0 then
begin
sl := TStringList.Create;
try
sl.Add(’’);
sl.Add(‘Now Playing’);
sl.Add(’’);
sl.Add(‘

We are not playing music right now…
stay tuned!

’);
sl.Add(’’);
sl.Add(’’);
sl.SaveToFile(‘c:\NowPlaying.html’);
finally
sl.Free;
end;
end;
end;

begin
end.
[/code]

Please note that you should not usually put any vars before the procedures in a Notification script: this one is only there so that BOTH the procedures can use and modify it.

If you want to ‘see’ or check what’s happening in the script, uncomment the two SystemLog lines and watch the system log area as you play items and start/stop players. (Remember to comment the lines OUT again afterwards: or just delete them!)

The script does contain a ‘bombproofing’ line so that if the number of ‘playing’ players ever goes negative (which should never happen), it will write a message to the system log to tell you, and it will also correct itself. 8)

As with the supplied notification scripts, this one is purely an example and you should tweak it to write the information you actually wish to write, change the file names/locations etc., and test it thoroughly before you use it ‘for real.’

PS: I changed the Item.GetArtist in Torben’s original script to the preferred Item.GetArtistsString used in v3.x. This means the script will work even if a track has multiple artists. :wink:

BFN
CAD