Re: [fpc-pascal] mciSendString with long file names
On 22-9-2022 21:26, Travis Siegel via fpc-pascal wrote: That's on windows, you said the program was running on linux. Afaik he said he was on Windows, but his files are on a Linux server: James richter Wrote: I just figured out that short filenames won't work, my files are on a linux server... not NTFS drives Probably it is something of either escaped spaces or ", but not both? Or simply a broken file system driver and an api that isn't very hardened against FS problems. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
Dennis Lee Bieber via fpc-pascal schrieb am Fr., 23. Sep. 2022, 04:10: >If FP is attempting to translate \ into some escape code, you > might try doubling the backslashes... C:\\Program Files\\My Program\\... > (I'm presuming "Progam" is a typo. > FPC has no need for that as "\" isn't used as an escape character, unlike for C. Regards, Sven > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
A solution I started using, because the mci commands (for some reason) don't handle all mp3 files I have, was to use a dll called fmod.dll. It handles several formats, not just mp3, and it can be started on another thread, then ignored. I've used it to build a much better mp3 player than I was able to make using the mci commands, since now I can handle other formats as well, which helps since interestingly enough, I'm still finding files in other formats burried in my collections, and so far, the fmod program handles them all nicely It can't be used in a commercial application, but it doesn't sound like yours is, so you should be ok. On 9/22/2022 4:22 PM, James Richters wrote: Sorry for the confusion. Let me clarify: The freepasal program is always run on a Windows system, mciSendString is a Windows function. I've seen solutions for this problem that use the NTFS 8.3 Short file name... Which I thought would work, but, for my application it won't work because the file is being loaded off a network drive, and the SERVER for the file is a Linux server.. but even though it's a Linux server, the path on my windows system is still uses backslashes not forward slashes... It's a FreeNAS server with Windows file sharing. Anyway the point was that only windows NTFS formatted drives have the short file name.. so that solution won't work at all. I want the program to be able to play the sound file no matter where the file is stored on the network or on a flash drive or a ramdrive.. etc, and not have a requirement that it is an NTFS drive. So it has to work with windows paths. Almost all windows applications just put it in quotes, but mciSendString does not play nice. I think it was invented during 8.3 limitations and it was only hacked to kind of work with long file names.. not really work properly. The Alias method does work, but it's not so convenient for Asynchronous mode because it leaves the file open.. if you close it before it finishes playing, it stops and if you wait for it to finish and then close it.. well, that's just not asynchronous. James -Original Message- From: fpc-pascal On Behalf Of Travis Siegel via fpc-pascal Sent: Thursday, September 22, 2022 3:27 PM To: ja...@productionautomation.net; FPC-Pascal users discussions Cc: Travis Siegel ; James Richters Subject: Re: [fpc-pascal] mciSendString with long file names That's on windows, you said the program was running on linux. In that case, backslashes will escape the spaces, allowing the path to be found properly. Windows paths are different, as mentioned before, they can be escaped too, but the character is different. On 9/22/2022 2:57 PM, James Richters via fpc-pascal wrote: Won’t backslashes before each space be defining a subdirectory? If my path looks like: C:\Program Files\My Program\Some File.MP3 I don't see how changing it to: C:\Program\ Files\My\ Progam\Some\ File.MP3 can possibly work.. it's just butchering the path. James From: fpc-pascal On Behalf Of Travis Siegel via fpc-pascal Sent: Wednesday, September 21, 2022 4:15 PM To: FPC-Pascal users discussions Cc: Travis Siegel ; Jean SUZINEAU Subject: Re: [fpc-pascal] mciSendString with long file names Adding a backslash (\) before each space should do the job nicely. I have had similar issues on linux and windows with some commands, and adding the escape characters to the filename almost always fixes the problem. The only time it didn't, was when the filename started with a dash "-" character. Otherwise, the backslash always works for me. On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote: May be by escaping the spaces with ^ ? Something like: MyFileName:= StringReplace(MyFileName, ' ', '^ ', [rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in this context too ? Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit : I just tried it that way: Var pcmd: String; MyFileName: String; pcmd:='play "'+MyFileName+'"'+#0; mciSendString(@pcmd[1],Nil,0,0); ___ fpc-pascal maillist - mailto:fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
Sorry for the confusion. Let me clarify: The freepasal program is always run on a Windows system, mciSendString is a Windows function. I've seen solutions for this problem that use the NTFS 8.3 Short file name... Which I thought would work, but, for my application it won't work because the file is being loaded off a network drive, and the SERVER for the file is a Linux server.. but even though it's a Linux server, the path on my windows system is still uses backslashes not forward slashes... It's a FreeNAS server with Windows file sharing. Anyway the point was that only windows NTFS formatted drives have the short file name.. so that solution won't work at all. I want the program to be able to play the sound file no matter where the file is stored on the network or on a flash drive or a ramdrive.. etc, and not have a requirement that it is an NTFS drive. So it has to work with windows paths. Almost all windows applications just put it in quotes, but mciSendString does not play nice. I think it was invented during 8.3 limitations and it was only hacked to kind of work with long file names.. not really work properly. The Alias method does work, but it's not so convenient for Asynchronous mode because it leaves the file open.. if you close it before it finishes playing, it stops and if you wait for it to finish and then close it.. well, that's just not asynchronous. James -Original Message- From: fpc-pascal On Behalf Of Travis Siegel via fpc-pascal Sent: Thursday, September 22, 2022 3:27 PM To: ja...@productionautomation.net; FPC-Pascal users discussions Cc: Travis Siegel ; James Richters Subject: Re: [fpc-pascal] mciSendString with long file names That's on windows, you said the program was running on linux. In that case, backslashes will escape the spaces, allowing the path to be found properly. Windows paths are different, as mentioned before, they can be escaped too, but the character is different. On 9/22/2022 2:57 PM, James Richters via fpc-pascal wrote: > Won’t backslashes before each space be defining a subdirectory? > > If my path looks like: > C:\Program Files\My Program\Some File.MP3 I don't see how changing it > to: > C:\Program\ Files\My\ Progam\Some\ File.MP3 can possibly work.. it's just > butchering the path. > > James > > > From: fpc-pascal On Behalf > Of Travis Siegel via fpc-pascal > Sent: Wednesday, September 21, 2022 4:15 PM > To: FPC-Pascal users discussions > Cc: Travis Siegel ; Jean SUZINEAU > > Subject: Re: [fpc-pascal] mciSendString with long file names > > Adding a backslash (\) before each space should do the job nicely. I have > had similar issues on linux and windows with some commands, and adding the > escape characters to the filename almost always fixes the problem. The only > time it didn't, was when the filename started with a dash "-" character. > Otherwise, the backslash always works for me. > > On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote: > May be by escaping the spaces with ^ ? > Something like: MyFileName:= StringReplace(MyFileName, ' ', '^ ', > [rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in > this context too ? > Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit : > I just tried it that way: > Var > pcmd: String; > MyFileName: String; > > pcmd:='play "'+MyFileName+'"'+#0; > mciSendString(@pcmd[1],Nil,0,0); > > > > > ___ > fpc-pascal maillist - mailto:fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
That's on windows, you said the program was running on linux. In that case, backslashes will escape the spaces, allowing the path to be found properly. Windows paths are different, as mentioned before, they can be escaped too, but the character is different. On 9/22/2022 2:57 PM, James Richters via fpc-pascal wrote: Won’t backslashes before each space be defining a subdirectory? If my path looks like: C:\Program Files\My Program\Some File.MP3 I don't see how changing it to: C:\Program\ Files\My\ Progam\Some\ File.MP3 can possibly work.. it's just butchering the path. James From: fpc-pascal On Behalf Of Travis Siegel via fpc-pascal Sent: Wednesday, September 21, 2022 4:15 PM To: FPC-Pascal users discussions Cc: Travis Siegel ; Jean SUZINEAU Subject: Re: [fpc-pascal] mciSendString with long file names Adding a backslash (\) before each space should do the job nicely. I have had similar issues on linux and windows with some commands, and adding the escape characters to the filename almost always fixes the problem. The only time it didn't, was when the filename started with a dash "-" character. Otherwise, the backslash always works for me. On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote: May be by escaping the spaces with ^ ? Something like: MyFileName:= StringReplace(MyFileName, ' ', '^ ', [rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in this context too ? Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit : I just tried it that way: Var pcmd: String; MyFileName: String; pcmd:='play "'+MyFileName+'"'+#0; mciSendString(@pcmd[1],Nil,0,0); ___ fpc-pascal maillist - mailto:fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
Won’t backslashes before each space be defining a subdirectory? If my path looks like: C:\Program Files\My Program\Some File.MP3 I don't see how changing it to: C:\Program\ Files\My\ Progam\Some\ File.MP3 can possibly work.. it's just butchering the path. James From: fpc-pascal On Behalf Of Travis Siegel via fpc-pascal Sent: Wednesday, September 21, 2022 4:15 PM To: FPC-Pascal users discussions Cc: Travis Siegel ; Jean SUZINEAU Subject: Re: [fpc-pascal] mciSendString with long file names Adding a backslash (\) before each space should do the job nicely. I have had similar issues on linux and windows with some commands, and adding the escape characters to the filename almost always fixes the problem. The only time it didn't, was when the filename started with a dash "-" character. Otherwise, the backslash always works for me. On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote: May be by escaping the spaces with ^ ? Something like: MyFileName:= StringReplace(MyFileName, ' ', '^ ', [rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in this context too ? Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit : I just tried it that way: Var pcmd: String; MyFileName: String; pcmd:='play "'+MyFileName+'"'+#0; mciSendString(@pcmd[1],Nil,0,0); ___ fpc-pascal maillist - mailto:fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
Adding a backslash (\) before each space should do the job nicely. I have had similar issues on linux and windows with some commands, and adding the escape characters to the filename almost always fixes the problem. The only time it didn't, was when the filename started with a dash "-" character. Otherwise, the backslash always works for me. On 9/20/2022 4:16 PM, Jean SUZINEAU via fpc-pascal wrote: May be by escaping the spaces with ^ ? Something like: MyFileName:= StringReplace(MyFileName, ' ', '^ ', [rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in this context too ? Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit : I just tried it that way: Var pcmd: String; MyFileName: String; pcmd:='play "'+MyFileName+'"'+#0; mciSendString(@pcmd[1],Nil,0,0); ___ fpc-pascal maillist -fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
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 On Behalf Of James Richters via fpc-pascal Sent: Tuesday, September 20, 2022 5:21 PM To: 'FPC-Pascal users discussions' Cc: James Richters ; 'Alexander Hofmann' 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@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
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@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
May be by escaping the spaces with ^ ? Something like: MyFileName:= StringReplace(MyFileName, ' ', '^ ', [rfReplaceAll]); ^ is the escape char for cmd.exe but may be it is active in this context too ? Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit : I just tried it that way: Var pcmd: String; MyFileName: String; pcmd:='play "'+MyFileName+'"'+#0; mciSendString(@pcmd[1],Nil,0,0); ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
Hi, I'm not so sure if that's an FPC-only issue. MCI commands like that have been around for a while, so spaces might not have been "considered" in the first place. A workaround was presented years ago, I can only find the archived version: https://ftp.zx.net.nz/pub/archive/ftp.microsoft.com/MISC/KB/en-us/191/089.HTM Basically, they suggested to create an alias to the file first using MCI "open" first, and then issue "play" on that alias instead of the filename. Best, Alex Am 20. September 2022 19:21:08 MESZ schrieb James Richters via fpc-pascal : >I just figured out that short filenames won't work, my files are on a linux >server... not NTFS drives.. so I'm back to getting it to work with spaces >the normal file names >James > >___ >fpc-pascal maillist - fpc-pascal@lists.freepascal.org >https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
I just figured out that short filenames won't work, my files are on a linux server... not NTFS drives.. so I'm back to getting it to work with spaces the normal file names James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
I just tried it that way: Var pcmd: String; MyFileName: String; pcmd:='play "'+MyFileName+'"'+#0; mciSendString(@pcmd[1],Nil,0,0); I get the same results, files with no spaces in the name even long file names play fine, if there's spaces, they won't play. I had the idea to just get the windows short file name and pass it on to play the sound instead of bothering to figure out why spaces won't work. I found getshortpathname: https://www.freepascal.org/daily/packages/winunits-jedi/jwawinbase/getshortp athname.html function GetShortPathName( lpszLongPath: LPCTSTR; lpszShortPath: LPTSTR; cchBuffer: Windows.DWORD ):Windows.DWORD; does anyone know how to convert a pascal string to the LPCTSTR needed for the long path and then how to convert the LPTSTR short path to LPCTSTR for mciSendString? Are the LPCTSTR and LPTSTR just PChar strings or something else? James >I've only ever done this like: > >pcmd: string; > >pcmd:='open "'+filename+'" ... '+#0; > >mciSendString(@pcmd[1], ...); ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] mciSendString with long file names
I've only ever done this like: pcmd: string; pcmd:='open "'+filename+'" ... '+#0; mciSendString(@pcmd[1], ...); mciSendString does return errors.. duno if that'll be helpful. I originally used it in Virtual Pascal and had to make a partial header myself so the FreePascal one might take parameters differently. From: fpc-pascal on behalf of James Richters via fpc-pascal Sent: Tuesday, September 20, 2022 9:56:03 AM To: 'FPC-Pascal users discussions' Cc: James Richters Subject: [fpc-pascal] mciSendString with long file names I’m trying to get mciSendString() to work with long file names with spaces in them and I’m not having any success. I know with winnows you need quotes around long file names, so I’m trying things like this: Var MySoundFile:String; mciSendString(PChar('play '+Ansistring(#34+MySoundFile+#34)),Nil,0,0); But still it works if my file name has no spaces, but does not work if there are spaces. I think maybe it’s my conversion to a PChar, but it works as long as there are no spaces, so I don’t know. The name of my file is in a string because it comes from a record with a string variable in it.. part of another whole system that I don’t want to change just to get this to work. Any one have any ideas how to get long file names with spaces to work? James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] mciSendString with long file names
I'm trying to get mciSendString() to work with long file names with spaces in them and I'm not having any success. I know with winnows you need quotes around long file names, so I'm trying things like this: Var MySoundFile:String; mciSendString(PChar('play '+Ansistring(#34+MySoundFile+#34)),Nil,0,0); But still it works if my file name has no spaces, but does not work if there are spaces. I think maybe it's my conversion to a PChar, but it works as long as there are no spaces, so I don't know. The name of my file is in a string because it comes from a record with a string variable in it.. part of another whole system that I don't want to change just to get this to work. Any one have any ideas how to get long file names with spaces to work? James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal