Page 1 of 1

unicode filenames problem

Posted: 11 Dec 2008 10:05
by innerspace
Im having problems playing videos with non-ANSI (thai) filenames using 0.9.6 and Kairos's Interop wrapper.

When feeding a thai file into a new VlcMedia I can see the proper name passed in, but checking the VlcMedia properties on the next line of debugging shows ???? instead of the thai characters.

The problem appears to be due to libvlc_media_new using unmanagedtype.LPstr

This is a single byte ANSI string, whereas I need unicode to read thai characters.

I have tried building a new version of the Interop Wrapper using BStr, LPTStr and LPWStr but none of these function at all.

I know that unicode filename support is possible since VLC plays them fine, I just need to replicate that in .Net!

Any ideas?

Here is a bit of Thai text incase it helps with testing (แจ้งรายการ)

Re: unicode filenames problem

Posted: 12 Dec 2008 06:55
by Kairos
Hmm... I think libvlc is using char* which is utf8 where C# is utf16. You would probably have to marshal it as a byte array

Code: Select all

[DllImport("libvlc")] internal static extern IntPtr libvlc_media_new(IntPtr p_instance, [MarshalAs(UnmanagedType.LPArray)] byte[] psz_mrl, ref libvlc_exception_t p_exception);
If you do this you need to encode the string before you pass it in like this;

Code: Select all

InteropMethods.libvlc_media_new(p_instance, System.Text.Encoding.UTF8.GetBytes(MRL) , ref p_exception);
This is just off the top of my head, I haven't tested it.

Re: unicode filenames problem

Posted: 15 Dec 2008 23:32
by billy_mo
I've the same problem when programming in VC++. I have to convert the UTF16 string to UTF8 string using the WideCharToMultiByte function.

Re: unicode filenames problem

Posted: 07 Feb 2009 12:39
by MidnightCoder
Can you explain the solution to fix this? I'm having the same issue.

Re: unicode filenames problem

Posted: 07 Feb 2009 13:31
by MidnightCoder
Hmm... I think libvlc is using char* which is utf8 where C# is utf16. You would probably have to marshal it as a byte array

Code: Select all

[DllImport("libvlc")] internal static extern IntPtr libvlc_media_new(IntPtr p_instance, [MarshalAs(UnmanagedType.LPArray)] byte[] psz_mrl, ref libvlc_exception_t p_exception);
If you do this you need to encode the string before you pass it in like this;

Code: Select all

InteropMethods.libvlc_media_new(p_instance, System.Text.Encoding.UTF8.GetBytes(MRL) , ref p_exception);
This is just off the top of my head, I haven't tested it.
Confirmed that this method works. Thanks a bunch!