Commit 4421c4c7 authored by Martin Finkel's avatar Martin Finkel

Mac: Support dylib instead of framework, enabling .NET Core Mac support

parent 45e3984f
This diff is collapsed.
......@@ -12,11 +12,14 @@ namespace LibVLCSharp.Shared
{
struct Native
{
[DllImport("kernel32.dll", SetLastError = true)]
[DllImport(Constants.Kernel32, SetLastError = true)]
internal static extern IntPtr LoadPackagedLibrary(string dllToLoad);
[DllImport("kernel32.dll", SetLastError = true)]
[DllImport(Constants.Kernel32, SetLastError = true)]
internal static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport(Constants.libSystem)]
internal static extern IntPtr dlopen(string libraryPath, int mode = 1);
#if ANDROID
[DllImport(Constants.LibraryName, EntryPoint = "JNI_OnLoad")]
internal static extern int JniOnLoad(IntPtr javaVm, IntPtr reserved = default(IntPtr));
......@@ -86,9 +89,17 @@ namespace LibVLCSharp.Shared
throw new VLCException($"Failed to load required native library {Constants.LibraryName}.dll");
}
}
else if (IsMac)
{
_libvlcHandle = PreloadNativeLibrary(appExecutionDirectory, $"{Constants.LibraryName}.dylib");
if (_libvlcHandle == IntPtr.Zero)
{
throw new VLCException($"Failed to load required native library {Constants.LibraryName}.dylib");
}
}
}
//TODO: check if Store app
//TODO: Add dlopen for UWP, Linux
static IntPtr PreloadNativeLibrary(string nativeLibrariesPath, string libraryName)
{
Debug.WriteLine($"Loading {libraryName}");
......@@ -101,7 +112,7 @@ namespace LibVLCSharp.Shared
return IntPtr.Zero;
}
#endif
return Native.LoadLibrary(libraryPath);// TODO: cross-platform load
return IsMac ? Native.dlopen(libraryPath) : Native.LoadLibrary(libraryPath);
}
static bool IsWindows
......@@ -113,22 +124,22 @@ namespace LibVLCSharp.Shared
#endif
}
static bool IsX64BitProcess
static bool IsMac
{
#if NET40
get => Environment.Is64BitProcess;
get => (int)Environment.OSVersion.Platform == 6;
#else
get => RuntimeInformation.OSArchitecture == Architecture.X64;
get => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
}
static bool IsX64BitProcess => IntPtr.Size == 8;
}
internal static class Constants
{
#if IOS
internal const string LibraryName = "@rpath/DynamicMobileVLCKit.framework/DynamicMobileVLCKit";
#elif MAC
internal const string LibraryName = "@rpath/VLCKit.framework/VLCKit";
#elif UNITY_ANDROID
/// <summary>
/// The vlc-unity C++ plugin which handles rendering (opengl/d3d) libvlc callbacks
......@@ -153,6 +164,7 @@ namespace LibVLCSharp.Shared
internal const string Msvcrt = "msvcrt";
internal const string Libc = "libc";
internal const string libSystem = "libSystem";
internal const string Kernel32 = "kernel32";
}
internal static class ArchitectureNames
......
......@@ -99,5 +99,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
<Import Project="..\..\packages\VideoLAN.LibVLC.Mac.3.1.2-alpha\build\VideoLAN.LibVLC.Mac.targets" Condition="Exists('..\..\packages\VideoLAN.LibVLC.Mac.3.1.2-alpha\build\VideoLAN.LibVLC.Mac.targets')" />
<Import Project="..\..\packages\VideoLAN.LibVLC.Mac.3.1.2\build\VideoLAN.LibVLC.Mac.targets" Condition="Exists('..\..\packages\VideoLAN.LibVLC.Mac.3.1.2\build\VideoLAN.LibVLC.Mac.targets')" />
</Project>
\ No newline at end of file
......@@ -22,6 +22,8 @@ namespace LibVLCSharp.Mac.Sample
{
base.ViewDidLoad();
Core.Initialize();
_libVLC = new LibVLC();
_mediaPlayer = new Shared.MediaPlayer(_libVLC);
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="VideoLAN.LibVLC.Mac" version="3.1.2-alpha" targetFramework="xamarinmac20" />
<package id="VideoLAN.LibVLC.Mac" version="3.1.2" targetFramework="xamarinmac20" />
</packages>
\ No newline at end of file
......@@ -3,10 +3,11 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>net47</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<RuntimeIdentifiers>win7-x64;win7-x86</RuntimeIdentifiers>
<RuntimeIdentifiers>win7-x64;win7-x86;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.4" />
<PackageReference Include="VideoLAN.LibVLC.Mac" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\LibVLCSharp\LibVLCSharp.csproj" />
......
using System;
using LibVLCSharp.Shared;
namespace LibVLCSharp.Windows.Sample
namespace LibVLCSharp.NetCore.Sample
{
class Program
{
......
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