[fpc-pascal] mciSendString with long file names

James Richters james.richters at productionautomation.net
Wed Sep 21 01:23:26 CEST 2022


I ran into a problem just removing spaces for the alias name,  I guess the
slashes and colon from the path are not valid for the alias, 
 so now I have a new function that removes everything that is not a letter,
and that seems to have solved the problem:

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

I'm still trying to see if there is a way to close everything even if I
don't know the alias anymore.

James

-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of
James Richters via fpc-pascal
Sent: Tuesday, September 20, 2022 5:21 PM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Cc: James Richters <james.richters at productionautomation.net>; 'Alexander
Hofmann' <Alexander.hofmann at new-h.de>
Subject: Re: [fpc-pascal] mciSendString with long file names

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.

James

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list