Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cf2464
commit f55b986
Showing
19 changed files
with
835 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
LibVLCSharp.Forms.Platforms.GTK/LibVLCSharp.Forms.Platforms.GTK.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net47</TargetFramework> | ||
</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"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<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/5.12.0/lib/mono/gtk-sharp-2.0/gdk-sharp.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="glib-sharp"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<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/5.12.0/lib/mono/gtk-sharp-2.0/glib-sharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="gtk-sharp"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<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/5.12.0/lib/mono/gtk-sharp-2.0/gtk-sharp.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net47</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="gdk-sharp"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<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/5.12.0/lib/mono/gtk-sharp-2.0/gdk-sharp.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="glib-sharp"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<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/5.12.0/lib/mono/gtk-sharp-2.0/glib-sharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="gtk-sharp"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<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/5.12.0/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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Gdk; | ||
using Gtk; | ||
using LibVLCSharp.Shared; | ||
|
||
namespace LibVLCSharp.GTK | ||
{ | ||
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); | ||
|
||
[DllImport("libgdk-quartz-2.0.0.dylib")] | ||
internal static extern IntPtr gdk_quartz_window_get_nsview(IntPtr handle); | ||
} | ||
|
||
private MediaPlayer _mediaPlayer; | ||
|
||
public VideoView(MediaPlayer mediaPlayer = null) | ||
{ | ||
_mediaPlayer = mediaPlayer; | ||
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.