Commit a927af51 authored by Jérémy VIGNELLES's avatar Jérémy VIGNELLES Committed by Martin Finkel

Add GTK# support

This commit contains a LibVLCSharp integration with GTK with optional
Xamarin.Forms support. It works on Linux and Windows only
(see https://github.com/mono/gtk-sharp/issues/257 as to why).

(cherry picked from commit baf5d7c0bf505f3b797fc13f6a08e575db833add)
parent c954cad1
......@@ -6,7 +6,10 @@
<DefineConstants>$(DefineConstants);NETSTANDARD1_1;NETSTANDARD</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
<DefineConstants>$(DefineConstants);NET40</DefineConstants>
<DefineConstants>$(DefineConstants);NET40;NET</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net471'">
<DefineConstants>$(DefineConstants);NET471;NET</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
<DefineConstants>$(DefineConstants);MONO;IOS;COCOA</DefineConstants>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Title>LibVLCSharp.Forms.GTK</Title>
<Summary>GTK integration for LibVLCSharp.Forms</Summary>
<Description>LibVLCSharp is a cross-platform audio and video API for .NET platforms based on VideoLAN's LibVLC Library.
It provides a comprehensive multimedia API that can be used across mobile, server and desktop to render video and output audio. Mono, .NET Framework and .NET Core runtimes are supported.
Supported platforms:
- Xamarin.Android
- Xamarin.iOS
- Xamarin.Mac
- Windows (WPF/WinForms)
- Xamarin.Forms
- .NET Standard 1.1
- .NET Core
Features:
- Network browsing for distant filesystems (SMB, FTP, SFTP, NFS...).
- HDMI passthrough for Audio HD codecs, like E-AC3, TrueHD or DTS-HD.
- Stream to distant renderers, like Chromecast.
- 360 video and 3D audio playback with viewpoint change.
- Support for Ambisonics audio and more than 8 audio channels.
- Subtitles size modification live.
- Hardware decoding and display on all platforms.
- DVD playback and menu navigation.
</Description>
<TargetFramework>net47</TargetFramework>
<RootNamespace>LibVLCSharp.Forms.GTK</RootNamespace>
<PackageVersion>0.0.1</PackageVersion>
<PackageId>LibVLCSharp.Forms.GTK</PackageId>
<Authors>VideoLAN</Authors>
<Owners>VideoLAN</Owners>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
<PackageLicenseExpression>LGPL-2.1-or-later</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://code.videolan.org/videolan/LibVLCSharp</RepositoryUrl>
<PackageIconUrl>https://code.videolan.org/videolan/LibVLCSharp/raw/master/Assets/icon.png</PackageIconUrl>
<PackageReleaseNotes>https://code.videolan.org/videolan/LibVLCSharp/blob/master/NEWS</PackageReleaseNotes>
<PackageTags>libvlc;vlc;videolan;native;c/c++;video;audio;player;media;mediaplayer;codec;ffmpeg;xamarin;graphics;ios;android;linux;windows;macos;cross-platform</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms.Platform.GTK" Version="3.2.0.871581" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibVLCSharp.Forms\LibVLCSharp.Forms.csproj" />
<ProjectReference Include="..\LibVLCSharp.GTK\LibVLCSharp.GTK.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="gdk-sharp">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gdk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gdk-sharp-2.0/gdk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gdk-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="glib-sharp">
<Private>False</Private>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\glib-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/glib-sharp.dll</HintPath>
</Reference>
<Reference Include="gtk-sharp">
<Private>False</Private>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gtk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gtk-sharp-2.0/gtk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gtk-sharp.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
\ No newline at end of file
using LibVLCSharp.Forms.Platforms.GTK;
using LibVLCSharp.Forms.Shared;
using LibVLCSharp.Shared;
using Xamarin.Forms;
using Xamarin.Forms.Platform.GTK;
[assembly: ExportRenderer(typeof(LibVLCSharp.Forms.Shared.VideoView), typeof(VideoViewRenderer))]
namespace LibVLCSharp.Forms.Platforms.GTK
{
public class VideoViewRenderer : ViewRenderer<LibVLCSharp.Forms.Shared.VideoView, LibVLCSharp.GTK.VideoView>
{
LibVLCSharp.GTK.VideoView _videoView;
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
_videoView = new LibVLCSharp.GTK.VideoView();
SetNativeControl(_videoView);
}
if (e.OldElement != null)
{
e.OldElement.MediaPlayerChanged -= OnMediaPlayerChanged;
}
if (e.NewElement != null)
{
e.NewElement.MediaPlayerChanged += OnMediaPlayerChanged;
}
}
private void OnMediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e)
{
if (Control == null)
{
return;
}
Control.MediaPlayer = e.NewMediaPlayer;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_videoView?.Dispose();
}
}
}
\ No newline at end of file
......@@ -24,8 +24,9 @@ Features:
- Subtitles size modification live.
- Hardware decoding and display on all platforms.
- DVD playback and menu navigation.
</Description>
<TargetFrameworks>netstandard2.0;MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20</TargetFrameworks>
</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsPlatform('Linux'))">$(TargetFrameworks);MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20</TargetFrameworks>
<RootNamespace>LibVLCSharp.Forms</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>7.3</LangVersion>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Title>LibVLCSharp.GTK</Title>
<Summary>GTK integration for LibVLCSharp</Summary>
<Description>LibVLCSharp is a cross-platform audio and video API for .NET platforms based on VideoLAN's LibVLC Library.
It provides a comprehensive multimedia API that can be used across mobile, server and desktop to render video and output audio. Mono, .NET Framework and .NET Core runtimes are supported.
Supported platforms:
- Xamarin.Android
- Xamarin.iOS
- Xamarin.Mac
- Windows (WPF/WinForms)
- Xamarin.Forms
- .NET Standard 1.1
- .NET Core
Features:
- Network browsing for distant filesystems (SMB, FTP, SFTP, NFS...).
- HDMI passthrough for Audio HD codecs, like E-AC3, TrueHD or DTS-HD.
- Stream to distant renderers, like Chromecast.
- 360 video and 3D audio playback with viewpoint change.
- Support for Ambisonics audio and more than 8 audio channels.
- Subtitles size modification live.
- Hardware decoding and display on all platforms.
- DVD playback and menu navigation.
</Description>
<TargetFramework>net47</TargetFramework>
<RootNamespace>LibVLCSharp.GTK</RootNamespace>
<Version>0.0.1</Version>
<PackageId>LibVLCSharp.GTK</PackageId>
<Authors>VideoLAN</Authors>
<Owners>VideoLAN</Owners>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<PackageLicenseExpression>LGPL-2.1-or-later</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://code.videolan.org/videolan/LibVLCSharp</RepositoryUrl>
<PackageIconUrl>https://code.videolan.org/videolan/LibVLCSharp/raw/master/Assets/icon.png</PackageIconUrl>
<PackageReleaseNotes>https://code.videolan.org/videolan/LibVLCSharp/blob/master/NEWS</PackageReleaseNotes>
<PackageTags>libvlc;vlc;videolan;native;c/c++;video;audio;player;media;mediaplayer;codec;ffmpeg;xamarin;graphics;ios;android;linux;windows;macos;cross-platform</PackageTags>
</PropertyGroup>
<ItemGroup>
<Reference Include="gdk-sharp">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gdk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gdk-sharp-2.0/gdk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gdk-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="glib-sharp">
<Private>False</Private>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\glib-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/glib-sharp.dll</HintPath>
</Reference>
<Reference Include="gtk-sharp">
<Private>False</Private>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gtk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gtk-sharp-2.0/gtk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gtk-sharp.dll</HintPath>
</Reference>
<ProjectReference Include="..\LibVLCSharp\LibVLCSharp.csproj" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
using System;
using System.Runtime.InteropServices;
using Gdk;
using Gtk;
using LibVLCSharp.Shared;
namespace LibVLCSharp.GTK
{
/// <summary>
/// GTK VideoView for Windows, Linux and Mac.
/// Mac is currently unsupported (see https://github.com/mono/gtk-sharp/issues/257)
/// </summary>
public class VideoView : DrawingArea, IVideoView
{
struct Native
{
/// <summary>
/// Gets the window's HWND
/// </summary>
/// <remarks>Window only</remarks>
/// <param name="gdkWindow">The pointer to the GdkWindow object</param>
/// <returns>The window's HWND</returns>
[DllImport("libgdk-win32-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr gdk_win32_drawable_get_handle(IntPtr gdkWindow);
/// <summary>
/// Gets the window's XID
/// </summary>
/// <remarks>Linux X11 only</remarks>
/// <param name="gdkWindow">The pointer to the GdkWindow object</param>
/// <returns>The window's XID</returns>
[DllImport("libgdk-x11-2.0.so.0", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint gdk_x11_drawable_get_xid(IntPtr gdkWindow);
/// <summary>
/// Gets the nsview's handle
/// </summary>
/// <remarks>Mac only</remarks>
/// <param name="gdkWindow">The pointer to the GdkWindow object</param>
/// <returns>The nsview's handle</returns>
[DllImport("libgdk-quartz-2.0.0.dylib")]
internal static extern IntPtr gdk_quartz_window_get_nsview(IntPtr gdkWindow);
}
private MediaPlayer _mediaPlayer;
public VideoView()
{
Color black = Color.Zero;
Color.Parse("black", ref black);
ModifyBg(StateType.Normal, black);
Realized += (s, e) => Attach();
}
public MediaPlayer MediaPlayer
{
get
{
return _mediaPlayer;
}
set
{
if (ReferenceEquals(_mediaPlayer, value))
{
return;
}
Detach();
_mediaPlayer = value;
Attach();
}
}
void Attach()
{
if (!IsRealized || _mediaPlayer == null)
{
return;
}
if (PlatformHelper.IsWindows)
{
MediaPlayer.Hwnd = Native.gdk_win32_drawable_get_handle(GdkWindow.Handle);
}
else if (PlatformHelper.IsLinux)
{
MediaPlayer.XWindow = Native.gdk_x11_drawable_get_xid(GdkWindow.Handle);
}
else if (PlatformHelper.IsMac)
{
MediaPlayer.NsObject = Native.gdk_quartz_window_get_nsview(GdkWindow.Handle);
}
else
{
throw new PlatformNotSupportedException();
}
}
void Detach()
{
if (!IsRealized || _mediaPlayer == null)
{
return;
}
if (PlatformHelper.IsWindows)
{
MediaPlayer.Hwnd = IntPtr.Zero;
}
else if (PlatformHelper.IsLinux)
{
MediaPlayer.XWindow = 0;
}
else if (PlatformHelper.IsMac)
{
MediaPlayer.NsObject = IntPtr.Zero;
}
else
{
throw new PlatformNotSupportedException();
}
}
public override void Dispose()
{
Detach();
base.Dispose();
}
}
}
This diff is collapsed.
......@@ -25,8 +25,10 @@ Features:
- Hardware decoding and display on all platforms.
- DVD playback and menu navigation.
</Description>
<TargetFrameworks>netstandard2.0;netstandard1.1;MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20;net40</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard1.1;net40;net471</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsPlatform('Linux'))">$(TargetFrameworks);MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20</TargetFrameworks>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeAWindow</TargetsForTfmSpecificBuildOutput>
<RootNamespace>LibVLCSharp</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>7.3</LangVersion>
......
......@@ -24,6 +24,14 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, EntryPoint = "JNI_OnLoad")]
internal static extern int JniOnLoad(IntPtr javaVm, IntPtr reserved = default(IntPtr));
#endif
/// <summary>
/// Initializes the X threading system
/// </summary>
/// <remarks>Linux X11 only</remarks>
/// <returns>non-zero on success, zero on failure</returns>
[DllImport(Constants.libX11, CallingConvention = CallingConvention.Cdecl)]
internal static extern int XInitThreads();
}
static IntPtr _libvlccoreHandle;
......@@ -69,9 +77,9 @@ namespace LibVLCSharp.Shared
#endif
}
if (IsWindows)
if (PlatformHelper.IsWindows)
{
var arch = IsX64BitProcess ? ArchitectureNames.Win64 : ArchitectureNames.Win86;
var arch = PlatformHelper.IsX64BitProcess ? ArchitectureNames.Win64 : ArchitectureNames.Win86;
var librariesFolder = Path.Combine(appExecutionDirectory, Constants.LibrariesRepositoryFolderName, arch);
......@@ -89,7 +97,7 @@ namespace LibVLCSharp.Shared
throw new VLCException($"Failed to load required native library {Constants.LibraryName}.dll");
}
}
else if (IsMac)
else if (PlatformHelper.IsMac)
{
_libvlcHandle = PreloadNativeLibrary(appExecutionDirectory, $"{Constants.LibraryName}.dylib");
if (_libvlcHandle == IntPtr.Zero)
......@@ -97,6 +105,16 @@ namespace LibVLCSharp.Shared
throw new VLCException($"Failed to load required native library {Constants.LibraryName}.dylib");
}
}
else if (PlatformHelper.IsLinux)
{
// Initializes X threads before calling VLC. This is required for vlc plugins like the VDPAU hardware acceleration plugin.
if (Native.XInitThreads() == 0)
{
#if !NETSTANDARD1_1
Trace.WriteLine("XInitThreads failed");
#endif
}
}
}
//TODO: Add dlopen for UWP, Linux
......@@ -112,28 +130,8 @@ namespace LibVLCSharp.Shared
return IntPtr.Zero;
}
#endif
return IsMac ? Native.dlopen(libraryPath) : Native.LoadLibrary(libraryPath);
}
static bool IsWindows
{
#if NET40
get => Environment.OSVersion.Platform == PlatformID.Win32NT;
#else
get => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#endif
return PlatformHelper.IsMac ? Native.dlopen(libraryPath) : Native.LoadLibrary(libraryPath);
}
static bool IsMac
{
#if NET40
get => (int)Environment.OSVersion.Platform == 6;
#else
get => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
}
static bool IsX64BitProcess => IntPtr.Size == 8;
}
internal static class Constants
......@@ -160,6 +158,7 @@ namespace LibVLCSharp.Shared
internal const string Libc = "libc";
internal const string libSystem = "libSystem";
internal const string Kernel32 = "kernel32";
internal const string libX11 = "libX11";
}
internal static class ArchitectureNames
......
......@@ -60,12 +60,11 @@ namespace LibVLCSharp.Shared
EntryPoint = "libvlc_media_player_pause")]
internal static extern void LibVLCMediaPlayerPause(IntPtr mediaPlayer);
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_stop")]
internal static extern void LibVLCMediaPlayerStop(IntPtr mediaPlayer);
#if COCOA || NET40
#if COCOA || NET || NETSTANDARD
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_set_nsobject")]
internal static extern void LibVLCMediaPlayerSetNsobject(IntPtr mediaPlayer, IntPtr drawable);
......@@ -74,7 +73,7 @@ namespace LibVLCSharp.Shared
EntryPoint = "libvlc_media_player_get_nsobject")]
internal static extern IntPtr LibVLCMediaPlayerGetNsobject(IntPtr mediaPlayer);
#endif
#if NET || NETSTANDARD
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_set_xwindow")]
internal static extern void LibVLCMediaPlayerSetXwindow(IntPtr mediaPlayer, uint drawable);
......@@ -83,7 +82,6 @@ namespace LibVLCSharp.Shared
EntryPoint = "libvlc_media_player_get_xwindow")]
internal static extern uint LibVLCMediaPlayerGetXwindow(IntPtr mediaPlayer);
#if NETSTANDARD || NET40
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_set_hwnd")]
internal static extern void LibVLCMediaPlayerSetHwnd(IntPtr mediaPlayer, IntPtr drawable);
......@@ -92,12 +90,10 @@ namespace LibVLCSharp.Shared
EntryPoint = "libvlc_media_player_get_hwnd")]
internal static extern IntPtr LibVLCMediaPlayerGetHwnd(IntPtr mediaPlayer);
#endif
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_get_length")]
internal static extern long LibVLCMediaPlayerGetLength(IntPtr mediaPlayer);
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_get_time")]
internal static extern long LibVLCMediaPlayerGetTime(IntPtr mediaPlayer);
......@@ -729,7 +725,7 @@ namespace LibVLCSharp.Shared
/// </summary>
public void Stop() => Native.LibVLCMediaPlayerStop(NativeReference);
#if COCOA || NET40
#if COCOA || NET || NETSTANDARD
/// <summary>
/// Get the NSView handler previously set
/// return the NSView handler or 0 if none where set
......@@ -755,7 +751,7 @@ namespace LibVLCSharp.Shared
}
#endif
#if NETSTANDARD || NET40
#if NET || NETSTANDARD
/// <summary>
/// Set an X Window System drawable where the media player should render its video output.
/// The call takes effect when the playback starts. If it is already started, it might need to be stopped before changes apply.
......@@ -1779,7 +1775,7 @@ namespace LibVLCSharp.Shared
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCVolumeCb(IntPtr data, float volume, [MarshalAs(UnmanagedType.I1)] bool mute);
#endregion
#endregion
/// <summary>
/// Get the Event Manager from which the media player send event.
......@@ -1797,7 +1793,7 @@ namespace LibVLCSharp.Shared
}
}
#region events
#region events
public event EventHandler<MediaPlayerMediaChangedEventArgs> MediaChanged
{
......@@ -1979,7 +1975,7 @@ namespace LibVLCSharp.Shared
remove => EventManager.DetachEvent(EventType.MediaPlayerAudioVolume, value);
}
#endregion
#endregion
protected override void Dispose(bool disposing)
{
......
using System;
using System.Runtime.InteropServices;
namespace LibVLCSharp.Shared
{
public class PlatformHelper
{
public static bool IsWindows
{
#if NET40
get => Environment.OSVersion.Platform == PlatformID.Win32NT;
#else
get => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#endif
}
public static bool IsLinux
{
#if NET40
get => Environment.OSVersion.Platform == PlatformID.Unix;
#else
get => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
#endif
}
public static bool IsMac
{
#if NET40
get => false; // no easy way to detect Mac platform host at runtime under net471
#else
get => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
}
public static bool IsX64BitProcess => IntPtr.Size == 8;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
</configuration>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
<OutputType>WinExe</OutputType>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="VideoLAN.LibVLC.Windows" Version="3.0.4" />
<PackageReference Condition="$([MSBuild]::IsOsPlatform('OSX'))" Include="VideoLAN.LibVLC.Mac" Version="3.1.2" />
<ProjectReference Include="..\..\..\LibVLCSharp.Forms.Platforms.GTK\LibVLCSharp.Forms.Platforms.GTK.csproj" />
<ProjectReference Include="..\LibVLCSharp.Forms.Sample\LibVLCSharp.Forms.Sample.csproj" />
</ItemGroup>
<!-- GTK# creators don't provide a ready-to-use nuget package yet...
The official procedure states that you should add the reference by hand, by picking the file on your disk.
That's what I did here, but I edited it so that I can build on windows and on linux
-->
<ItemGroup>
<Reference Include="gdk-sharp">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gdk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gdk-sharp-2.0/gdk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gdk-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="glib-sharp">
<Private>False</Private>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\glib-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/glib-sharp.dll</HintPath>
</Reference>
<Reference Include="gtk-sharp">
<Private>False</Private>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gtk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gtk-sharp-2.0/gtk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gtk-sharp.dll</HintPath>
</Reference>
<Reference Include="atk-sharp">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\atk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/atk-sharp-2.0/atk-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/atk-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="glade-sharp">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\glade-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/glade-sharp-2.0/glade-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/glade-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="gtk-dotnet">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\gtk-dotnet.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/gtk-dotnet-2.0/gtk-dotnet.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gtk-dotnet.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="pango-sharp">
<HintPath Condition="$([MSBuild]::IsOsPlatform('Windows'))">C:\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\pango-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('Linux'))">/usr/lib/cli/pango-sharp-2.0/pango-sharp.dll</HintPath>
<HintPath Condition="$([MSBuild]::IsOsPlatform('OSX'))">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/pango-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Project>
\ No newline at end of file
<configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
<!-- XQuartz compatibility (X11 on Mac) -->
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
</configuration>
using System;
using LibVLCSharp.Forms.Shared;
using LibVLCSharp.Shared;
using Xamarin.Forms.Platform.GTK;
namespace LibVLCSharp.Forms.Sample.GTK
{
public class Program
{
[STAThread]
public static void Main(string[] args)
{
global::Gtk.Application.Init();
LibVLCSharpFormsRenderer.Init();
// For some reason, Xamarin does not pick the LibVLCSharp.Form.Platforms.Gtk assembly as a renderer assembly.
// Add it manually.
global::Xamarin.Forms.Forms.Init(new[] { typeof(LibVLCSharp.Forms.Platforms.GTK.VideoViewRenderer).Assembly });
var app = new App();
var window = new FormsWindow();
window.LoadApplication(app);
window.SetApplicationTitle("GTK# LibVLCSharp.Forms sample");
window.Show();
global::Gtk.Application.Run();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="VideoLAN.LibVLC.Windows" version="3.0.4" targetFramework="net47" />
<package id="Xamarin.Forms" version="3.2.0.871581" targetFramework="net47" />
<package id="Xamarin.Forms.Platform.GTK" version="3.2.0.871581" targetFramework="net47" />
</packages>
\ No newline at end of file
<configuration>
<dllmap dll="webkit-1.0" target="/usr/lib/x86_64-linux-gnu/libwebkitgtk-1.0.so"/>
</configuration>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
<OutputType>WinExe</OutputType>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>