[fpc-pascal] mciSendString with long file names

James Richters james.richters at productionautomation.net
Tue Sep 20 23:20:44 CEST 2022

That Alias method does seem to work.. thank you for the suggestion, although it makes it more complicated for asynchronous operation, which is of course what I wanted.

So here is what I came up with.. for synchronous operation, this works fine:
mciSendString(Pchar(Ansistring('Open ' + #34+MyLongFileName+#34 + ' alias myalias wait')), Nil, 0, 0);
mciSendString(PChar(Ansistring('Play myalias wait')), Nil, 0, 0);
mciSendString(PChar(Ansistring('Close myalias)), Nil, 0, 0);

but without the wait, it closes before it plays.. and I don't want my application to wait for the sound to finish before moving on, 
so for asynchronous operation, I just put the close before the open and it seems to work, to make sure the alias is available, and it seems to work.  
I also need unique alias names, in case 2 sounds are trying to be played back to back, otherwise the second one will not be able to use the alias
but that's easy to generate by just removing the spaces from the file name.
This seems to work:

mciSendString(PChar(Ansistring('Close '+Nospaces(MyLongFileName))), Nil, 0, 0);
mciSendString(Pchar(Ansistring('Open ' + #34+MyLongFileName+#34 + ' alias '+Nospaces(MyLongFileName))), Nil, 0, 0);
mciSendString(PChar(Ansistring('Play '+Nospaces(MyLongFileName)+' wait')), Nil, 0, 0);

I suppose I really need to close it at some point after it's done, but by then my process is long past the procedure that fired it off... at least for repeat playing, it will have closed the old one before it made a new one.

I wonder if there is a way to do a 'CLOSE ALL' that I could run when before my program exits just to clean up the system.


More information about the fpc-pascal mailing list