I’m new to scripting and am trying to find out is this here is possible at all:
I’d like a run an external program that creates a new mp3 file
(here e:\test\new.mp3). As soon as it is created, it should be
inserted to play as the next object in the current running playlist.
I’ve manage to get this script (which I found in the forum) to run.
Instead of the sleep command I’d rather wait until the
file has appeared or the ShellExecute is finished.
CurrentPlaylist.BeginUpdate;
try
activePlayer := -1;
for i := 0 to CurrentPlaylist.GetPlayerCount - 1 do
if CurrentPlaylist.GetPlayer(i).GetState = psPlaying then begin
activePlayer := i;
break;
end;
if activePlayer = -1 then begin
SystemLog('No player is active!');
CurrentPlaylist.Insert(CurrentPlaylist.GetNextIndex, newItem);
// no need to call AutomationNext here
exit;
end;
// Index of item that is currently playing
activeItem := CurrentPlaylist.GetPlayer(activePlayer).GetItem;
// Insert new item below
CurrentPlaylist.Insert(CurrentPlaylist.IndexOf(activeItem) + 1, newItem);
Can you please enter the serial number of your mAirList license into your forum profile? Thank you.
I’m currently evaluating the 30min demo version of the personal edition, so I do not have a license file yet. I’m trying to find out if I manage to understand the scripting enough before buying.
I’ll get one as soon as I figure out how to place sound files I just generated with an external tool into a running playlist to play as the next object after a fixed soft time. As a former Turbo Pascal programmer I should be able to do this, but so far I’ve not managed to find enough working code examples to modify a running playlist.
As soon as I buy a licence I’ll update the info in the profile.
Regarding the original question, you can use FileExists:
while not FileExists('e:\test\new.mp3') do Sleep(1000);
It might be a good idea to leave the loop with an error message after a particular number of rounds if the file still doesn’t exist - just in case the process didn’t complete for some reason.
i := 0;
while not FileExists('e:\test\new.mp3') do begin
if i = 10 then begin
SystemLog('File didn''t appear after 10 seconds.');
exit;
end;
Sleep(1000);
inc(i);
end;
The rest of the script you posted can be simplified a lot using GetNextIndex:
The GetNextIndex method returns the index of the item that is to be played next. If you insert the new item at exactly that position, it will be played next. The method didn’t exist in earlier versions of mAirList, this is why the original author of the script used a different way to determine the insert index.
Thanks for the quick reply. I just ordered a licence a few minutes ago.
Is there any reference to what I can do with scripts regarding the current playlist? I didn’t find anything in the manual and the wiki, so my only source for info was google-searching this forum which turns up a lot of outdated scripts that don’t work…
You don’t say whether you’re using mAirList V4 or V3.1: which is it?
If it’s V3.1, you’ll find that scripts such as IVP and YearJingleAdder (in the Scripts forum) can be downloaded and run as-is. I haven’t personally tried V4 yet: when I have the time to do that, I’ll write ‘V4’ versions of those scripts and post them in the Forum.
var
i: integer;
st : string;
t1 : TDateTime;
begin
// Generate a DateTime so use for a playlist item later
// Example 2011.10.02 at 16:15
t1 := now;
t1 := EncodeDate(2011, 10,2) + EncodeTime(16,15,0,0);
st := FormatDateTime('c', t1) ;
SystemLog('My time '+st);
end.