Commit 5febe9fe authored by Martin Finkel's avatar Martin Finkel

Fix media mrl UTF8 marshalling

(cherry picked from commit 18b1464145486812a63badccd76e11c5f5e243f5)
parent 814dd9a5
......@@ -17,5 +17,8 @@ namespace LibVLCSharp.Tests
protected string RealMp3Path =>
Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "sample.mp3");
protected string RealMp3PathSpecialCharacter =>
Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "motörhead.mp3");
}
}
\ No newline at end of file
......@@ -17,6 +17,9 @@
<ProjectReference Include="..\LibVLCSharp\LibVLCSharp.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="motörhead.mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="sample.mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......
......@@ -63,6 +63,7 @@ namespace LibVLCSharp.Tests
media.Parse();
Assert.True(media.IsParsed);
Assert.AreEqual(Media.MediaParsedStatus.Done, media.ParsedStatus);
Assert.NotZero(media.Duration);
using (var mp = new MediaPlayer(media))
{
......@@ -108,5 +109,35 @@ namespace LibVLCSharp.Tests
media.Parse();
Assert.AreEqual(1, media.Tracks);
}
[Test]
public async Task CreateRealMediaSpecialCharacters()
{
using (var libVLC = new LibVLC())
{
libVLC.Log += LibVLC_Log;
using (var media = new Media(libVLC, RealMp3PathSpecialCharacter, Media.FromType.FromPath))
{
Assert.False(media.IsParsed);
media.Parse();
await Task.Delay(5000);
Assert.True(media.IsParsed);
Assert.AreEqual(Media.MediaParsedStatus.Done, media.ParsedStatus);
using (var mp = new MediaPlayer(media))
{
Assert.True(mp.Play());
await Task.Delay(10000);
mp.Stop();
}
}
libVLC.Log -= LibVLC_Log;
}
}
private void LibVLC_Log(object sender, LogEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
}
}
\ No newline at end of file
......@@ -18,17 +18,17 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_new_location")]
internal static extern IntPtr LibVLCMediaNewLocation(IntPtr libVLC, [MarshalAs(UnmanagedType.LPStr)] string mrl);
internal static extern IntPtr LibVLCMediaNewLocation(IntPtr libVLC, IntPtr mrl);
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_new_path")]
internal static extern IntPtr LibVLCMediaNewPath(IntPtr libVLC, [MarshalAs(UnmanagedType.LPStr)] string path);
internal static extern IntPtr LibVLCMediaNewPath(IntPtr libVLC, IntPtr path);
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_new_as_node")]
internal static extern IntPtr LibVLCMediaNewAsNode(IntPtr libVLC, [MarshalAs(UnmanagedType.LPStr)] string name);
internal static extern IntPtr LibVLCMediaNewAsNode(IntPtr libVLC, IntPtr name);
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
......@@ -326,14 +326,18 @@ namespace LibVLCSharp.Shared
if (libVLC == null) throw new ArgumentNullException(nameof(libVLC));
if (string.IsNullOrEmpty(mrl)) throw new ArgumentNullException(nameof(mrl));
var mrlPtr = Utf8StringMarshaler.GetInstance().MarshalManagedToNative(mrl);
if (mrlPtr == IntPtr.Zero)
throw new ArgumentException($"error marshalling {mrl} to UTF-8 for native interop");
switch (type)
{
case FromType.FromLocation:
return Native.LibVLCMediaNewLocation(libVLC.NativeReference, mrl);
return Native.LibVLCMediaNewLocation(libVLC.NativeReference, mrlPtr);
case FromType.FromPath:
return Native.LibVLCMediaNewPath(libVLC.NativeReference, mrl);
return Native.LibVLCMediaNewPath(libVLC.NativeReference, mrlPtr);
case FromType.AsNode:
return Native.LibVLCMediaNewAsNode(libVLC.NativeReference, mrl);
return Native.LibVLCMediaNewAsNode(libVLC.NativeReference, mrlPtr);
default:
return IntPtr.Zero;
}
......
......@@ -59,7 +59,7 @@ namespace LibVLCSharp.Shared
return -1;
}
public static ICustomMarshaler GetInstance()
public static ICustomMarshaler GetInstance(string cookie = null)
{
return _instance;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment