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

Hi,

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

[code]
var
newItem: IPlaylistItem;
i: integer;
activePlayer: integer;
activeItem: IPlaylistItem;
curpos: TTimeValue;

begin

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

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

// Find better way to wait
Sleep(10000);

// schedule next

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

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

finally
CurrentPlaylist.EndUpdate;
end;
end.[/code]

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.');
    exit;
  end;
  Sleep(1000);
  inc(i);
end;

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: http://www.mairlist.com/download/mAirList/v3.1/scriptinghelp/

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.

BFN
Cad

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…
http://www.be-precision.com/products/precision-builder/express/webhelp/en/topics/PSSyntax.htm)

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.

I can also recommend http://www.delphibasics.co.uk/ 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.)