Var
FPlayerProcess: TProcessUTF8;
...
FPlayerProcess.Executable:=FMPlayerPath;
FPlayerProcess.Parameters.Add(AnsiToUTF8(Filename));
FPlayerProcess.Execute;
If I pass a non-unicode filename to this, everything works, and I get the following by querying FPlayerProcess.outputMPlayer Redxii-SVN-r37216-4.8.2 (i686) (C) 2000-2014 MPlayer TeamOn the other hand, if I pass a file with a unicode name ("skiing - ǤǥǦ.avi") into the procedure, then instead I see
Compiled against FFmpeg version N-63644-ge1bd40f
Build date: Sat May 31 22:08:38 EDT 2014
Playing B:\Code\Compile\Test Data\Clip_1080_5sec_VC1_15mbps.wmv.
...
MPlayer Redxii-SVN-r37216-4.8.2 (i686) (C) 2000-2014 MPlayer TeamI've confirmed from the command line that mplayer itself will play the file with the unicode filename. So it's looks like it's down to my handling of unicode filenames. Somehow I'm mangling "skiing - ǤǥǦ.avi" into "skiing - ǤǥǦ.avi"
Compiled against FFmpeg version N-63644-ge1bd40f
Build date: Sat May 31 22:08:38 EDT 2014
Playing B:\Code\Compile\Test Data\skiing - ǤǥǦ.avi.
Exiting... (End of file)
FPlayerProcess.Parameters.Add(AnsiToUTF8(Filename)); // mplayer reports can't find "skiing - ǤǥǦ.avi"
and
FPlayerProcess.Parameters.Add(Filename); // mplayer reports can't find "skiing - GgG.avi"
I tried UTF8ToSys (and SysToUTF8). No banana's each time :-(I use TProcessUTF8 without problems, (but not for mplayer), If you use TProcessUTF8 then you need UTF8 Parameters, you can't use UTF8ToSys, for that use TProcess. If command line works then Sys encoding works, hm... Can you remove spaces (from file name) for test ?
I didn't try TProcess, do you have experience of it working with unicode paramaters?
Can you remove spaces (from file name) for test ?Spaces in filenames were the first issue I resolved when working with this code. But I haven't tested the specific scenario of Unicode + No spaces. hang on....
AFAIK yo do not need to use Utf8ToSys, just supply the name as UTF8, the conversion is done inside the TProcessUtf8.
Bart
It seems that TProcessUTF8 does UTF8tosys() too internally. You can try the same with TProcess, but TProcess fundamentally doesn't understand unicode on Windows. Moreover it does some string processing that makes it shaky.
If your filename contains characters not in your windows codepage, it will probably fail miserably.
definitely TProcess.Execute which ultimately appears to call CreateProcessA, not CreateProcessW.
2.7.1 is being changed in that regard to use -W, but that hasn't progressed yet to anything classes based yet (but most system and sysutils routines are.
One last word on this issue promise :-)
Just letting people know that the issue appears limited to Windows. Identical code compiled under Linux (Mint 14/Mate) successfully opened the unicode file first try.
Avoid string problem,Yes, but TProcess.CommandLine is String.... how can i do it?
use "pchar(utf8encode(<unicodestring>))" is good way in fpc >= 2.7
RTL string function always assume dest encoding is "defaultsystemcodepage",
it make trouble sometimes.
@mdalacuCommandLine is deprecated. Since you need widestring, you're probably under windows. TProcess can be easily replaced with Createprocess, ShellExecute, ShellExecuteEx, etc..., or you can override a few methods in TProcess to accept widestrings, even better you only need to override the execute method with ExecuteUnicode.
Yes, but TProcess.CommandLine is String.... how can i do it?