Beginners question: How to wait until a sound file exists?


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.

Any hints on how to do this?

Thank you

newItem: IPlaylistItem;
i: integer;
activePlayer: integer;
activeItem: IPlaylistItem;
curpos: TTimeValue;


// Run an outside program that produces a new mp3 file

ShellExecute(‘e:\test\create_new_mp3.exe’, ‘parameter’);

// Find better way to wait

// schedule next

newItem := Factory.CreateFilePlaylistItem(‘e:\test\new.mp3’, []);

activePlayer := -1;
for i := 0 to CurrentPlaylist.GetPlayerCount - 1 do
if CurrentPlaylist.GetPlayer(i).GetState = psPlaying then begin
activePlayer := i;

if activePlayer = -1 then begin
  SystemLog('No player is active!');
  CurrentPlaylist.Insert(CurrentPlaylist.GetNextIndex, newItem);
  // no need to call AutomationNext here

// 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.

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.

Ok, understood.

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.');

The rest of the script you posted can be simplified a lot using GetNextIndex:

CurrentPlaylist.Insert(CurrentPlaylist.GetNextIndex, Factory.CreateFilePlaylistItem('e:\test\new.mp3', []));

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…

There’s a CHM “help file” available:

Hardly any methods are documented though. So you merely get a list of all methods - most have obvious names and parameters however.

If anything is unclear, just ask.

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.


Hi - very late reply - I’m using V3.1 for the time being.

My main interest is analysing and modifying the playlist.

#update# - answering my own question:

I withdraw my original question here, which was how
to create a DateTime object from time stored in integers.
(If anyone has a similar beginners problem,
this page would have saved me hours…

  i: integer;
  st : string;
  t1 : TDateTime;

 // 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);

I can also recommend for beginners.

(Pascal Script isn’t exactly Delphi, and not everything that works in Delphi does also work in Pascal Script, but most things do.)