Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #151 from microchi/master
Browse files Browse the repository at this point in the history
Add Get/Set Video Aspect Ratio With Sample
  • Loading branch information
ZeBobo5 committed Mar 17, 2016
2 parents 83a8359 + 4eb2df3 commit 3768b9d
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 5 deletions.
36 changes: 34 additions & 2 deletions src/Samples/Vlc.DotNet.Forms.Samples/Sample.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 49 additions & 1 deletion src/Samples/Vlc.DotNet.Forms.Samples/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void OnButtonPauseClicked(object sender, EventArgs e)
private void OnVlcMediaLengthChanged(object sender, Core.VlcMediaPlayerLengthChangedEventArgs e)
{
#if !NET20
myLblMediaLength.InvokeIfRequired(l => l.Text = new DateTime(new TimeSpan((long) e.NewLength).Ticks).ToString("T"));
myLblMediaLength.InvokeIfRequired(l => l.Text = new DateTime(new TimeSpan((long)e.NewLength).Ticks).ToString("T"));
#else
ControlExtensions.InvokeIfRequired(myLblMediaLength, l => l.Text = new DateTime(new TimeSpan((long)e.NewLength).Ticks).ToString("T"));
#endif
Expand Down Expand Up @@ -84,15 +84,30 @@ private void OnVlcStopped(object sender, Core.VlcMediaPlayerStoppedEventArgs e)
{
#if !NET20
myLblState.InvokeIfRequired(l => l.Text = "Stopped");

myCbxAspectRatio.InvokeIfRequired(c =>
{
c.Text = string.Empty;
c.Enabled = false;
});
#else
ControlExtensions.InvokeIfRequired(myLblState, c => c.Text = "Stopped");

ControlExtensions.InvokeIfRequired(myCbxAspectRatio, c =>
{
c.Text = string.Empty;
c.Enabled = false;
});
#endif
myLblAudioCodec.Text = "Codec: ";
myLblAudioChannels.Text = "Channels: ";
myLblAudioRate.Text = "Rate: ";
myLblVideoCodec.Text = "Codec: ";
myLblVideoHeight.Text = "Height: ";
myLblVideoWidth.Text = "Width: ";



}

private void OnVlcPlaying(object sender, Core.VlcMediaPlayerPlayingEventArgs e)
Expand Down Expand Up @@ -124,6 +139,11 @@ private void OnVlcPlaying(object sender, Core.VlcMediaPlayerPlayingEventArgs e)
}
}

myCbxAspectRatio.InvokeIfRequired(c =>
{
c.Text = myVlcControl.Video.AspectRatio;
c.Enabled = true;
});

#else
ControlExtensions.InvokeIfRequired(myLblState, c => c.Text = "Playing");
Expand Down Expand Up @@ -151,8 +171,36 @@ private void OnVlcPlaying(object sender, Core.VlcMediaPlayerPlayingEventArgs e)
ControlExtensions.InvokeIfRequired(myLblVideoWidth, c => c.Text += mediaInformation.Video.Width);
}
}

ControlExtensions.InvokeIfRequired(myCbxAspectRatio, c =>
{
c.Text = myVlcControl.Video.AspectRatio;
c.Enabled = true;
});
#endif
}

private void myCbxAspectRatio_TextChanged(object sender, EventArgs e)
{
myVlcControl.Video.AspectRatio = myCbxAspectRatio.Text;
ResizeVlcControl();
}

private void Sample_SizeChanged(object sender, EventArgs e)
{
ResizeVlcControl();
}

void ResizeVlcControl()
{
if (!string.IsNullOrEmpty(myCbxAspectRatio.Text))
{
var ratio = myCbxAspectRatio.Text.Split(':');
int width, height;
if (ratio.Length == 2 && int.TryParse(ratio[0], out width) && int.TryParse(ratio[1], out height))
myVlcControl.Width = myVlcControl.Height * width / height;
}
}

}
}
4 changes: 2 additions & 2 deletions src/Samples/Vlc.DotNet.Forms.Samples/Sample.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Runtime.InteropServices;

namespace Vlc.DotNet.Core.Interops.Signatures
{
/// <summary>
/// Get current crop filter geometry.
/// </summary>
[LibVlcFunction("libvlc_video_get_aspect_ratio")]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr GetVideoAspectRatio(IntPtr mediaPlayerInstance);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Runtime.InteropServices;

namespace Vlc.DotNet.Core.Interops.Signatures
{
/// <summary>
/// Set current crop filter geometry.
/// </summary>
[LibVlcFunction("libvlc_video_set_aspect_ratio")]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void SetVideoAspectRatio(IntPtr mediaPlayerInstance, IntPtr cropGeometry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_media_player_get_hwnd.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_media_player_get_length.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_media_player_get_time.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_take_snapshot.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_media_player_set_time.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_rectangle_t.cs" />
Expand Down Expand Up @@ -179,6 +181,8 @@
<Compile Include="VlcManager.GetLength.cs" />
<Compile Include="VlcManager.GetMediaPlayerVideoHostHandle.cs" />
<Compile Include="VlcManager.GetTime.cs" />
<Compile Include="VlcManager.GetVideoAspectRatio.cs" />
<Compile Include="VlcManager.SetVideoAspectRatio.cs" />
<Compile Include="VlcManager.TakeSnapshot.cs" />
<Compile Include="VlcManager.SetAudioDelay.cs" />
<Compile Include="VlcManager.SetAudioChannel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_adjust_option_t.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_adjust_float.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_adjust_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_crop_geometry.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_logo_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_marquee_int.cs" />
Expand All @@ -191,6 +192,7 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_marquee_option_t.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_adjust_float.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_adjust_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_crop_geometry.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_deinterlace.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_logo_int.cs" />
Expand Down Expand Up @@ -236,6 +238,7 @@
<Compile Include="VlcManager.GetMediaPlayerVideoHostHandle.cs" />
<Compile Include="VlcManager.GetTime.cs" />
<Compile Include="VlcManager.GetVideoAdjust.cs" />
<Compile Include="VlcManager.GetVideoAspectRatio.cs" />
<Compile Include="VlcManager.GetVideoCropGeometry.cs" />
<Compile Include="VlcManager.GetVideoLogo.cs" />
<Compile Include="VlcManager.GetVideoMarquee.cs" />
Expand Down Expand Up @@ -299,6 +302,7 @@
<Compile Include="VlcManager.SetRate.cs" />
<Compile Include="VlcManager.SetTime.cs" />
<Compile Include="VlcManager.SetVideoAdjust.cs" />
<Compile Include="VlcManager.SetVideoAspectRatio.cs" />
<Compile Include="VlcManager.SetVideoCropGeometry.cs" />
<Compile Include="VlcManager.SetVideoDeinterlace.cs" />
<Compile Include="VlcManager.SetVideoLogo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_adjust_option_t.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_adjust_float.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_adjust_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_crop_geometry.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_logo_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_marquee_int.cs" />
Expand All @@ -191,6 +192,7 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_marquee_option_t.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_adjust_float.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_adjust_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_crop_geometry.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_deinterlace.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_logo_int.cs" />
Expand All @@ -207,7 +209,9 @@
<Compile Include="VlcManager.GetLength.cs" />
<Compile Include="VlcManager.GetMediaPlayerVideoHostHandle.cs" />
<Compile Include="VlcManager.GetTime.cs" />
<Compile Include="VlcManager.GetVideoAspectRatio.cs" />
<Compile Include="VlcManager.SetTime.cs" />
<Compile Include="VlcManager.SetVideoAspectRatio.cs" />
<Compile Include="VlcManager.TakeSnapshot.cs" />
<Compile Include="VlcMediaEventManagerInstance.cs" />
<Compile Include="VlcMediaInstance.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_adjust_option_t.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_adjust_float.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_adjust_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_crop_geometry.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_logo_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_get_marquee_int.cs" />
Expand All @@ -196,6 +197,7 @@
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_marquee_option_t.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_adjust_float.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_adjust_int.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_aspect_ratio.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_crop_geometry.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_deinterlace.cs" />
<Compile Include="Signatures\libvlc_media_player.h\libvlc_video_set_logo_int.cs" />
Expand Down Expand Up @@ -257,6 +259,7 @@
<Compile Include="VlcManager.GetRate.cs" />
<Compile Include="VlcManager.GetTime.cs" />
<Compile Include="VlcManager.GetVideoAdjust.cs" />
<Compile Include="VlcManager.GetVideoAspectRatio.cs" />
<Compile Include="VlcManager.GetVideoCropGeometry.cs" />
<Compile Include="VlcManager.GetVideoFilterList.cs" />
<Compile Include="VlcManager.GetVideoLogo.cs" />
Expand Down Expand Up @@ -304,6 +307,7 @@
<Compile Include="VlcManager.SetRate.cs" />
<Compile Include="VlcManager.SetTime.cs" />
<Compile Include="VlcManager.SetVideoAdjust.cs" />
<Compile Include="VlcManager.SetVideoAspectRatio.cs" />
<Compile Include="VlcManager.SetVideoCropGeometry.cs" />
<Compile Include="VlcManager.SetVideoDeinterlace.cs" />
<Compile Include="VlcManager.SetVideoLogo.cs" />
Expand Down
19 changes: 19 additions & 0 deletions src/Vlc.DotNet.Core.Interops/VlcManager.GetVideoAspectRatio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Vlc.DotNet.Core.Interops.Signatures;

namespace Vlc.DotNet.Core.Interops
{
public sealed partial class VlcManager
{
public string GetVideoAspectRatio(VlcMediaPlayerInstance mediaPlayerInstance)
{
if (mediaPlayerInstance == IntPtr.Zero)
throw new ArgumentException("Media player instance is not initialized.");
#if NET20
return IntPtrExtensions.ToStringAnsi(GetInteropDelegate<GetVideoAspectRatio>().Invoke(mediaPlayerInstance));
#else
return GetInteropDelegate<GetVideoAspectRatio>().Invoke(mediaPlayerInstance).ToStringAnsi();
#endif
}
}
}
19 changes: 19 additions & 0 deletions src/Vlc.DotNet.Core.Interops/VlcManager.SetVideoAspectRatio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Vlc.DotNet.Core.Interops.Signatures;

namespace Vlc.DotNet.Core.Interops
{
public sealed partial class VlcManager
{
public void SetVideoAspectRatio(VlcMediaPlayerInstance mediaPlayerInstance, string cropGeometry)
{
if (mediaPlayerInstance == IntPtr.Zero)
throw new ArgumentException("Media player instance is not initialized.");
#if NET20
GetInteropDelegate<SetVideoAspectRatio>().Invoke(mediaPlayerInstance, StringExtensions.ToHGlobalAnsi(cropGeometry));
#else
GetInteropDelegate<SetVideoAspectRatio>().Invoke(mediaPlayerInstance, cropGeometry.ToHGlobalAnsi());
#endif
}
}
}
1 change: 1 addition & 0 deletions src/Vlc.DotNet.Core/IVideoManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public interface IVideoManagement
{
string AspectRatio { get; set; }
string CropGeometry { get; set; }
int Teletext { get; set; }
ITracksManagement Tracks { get; }
Expand Down
6 changes: 6 additions & 0 deletions src/Vlc.DotNet.Core/VideoManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public VideoManagement(VlcManager manager, VlcMediaPlayerInstance mediaPlayerIns
Logo = new LogoManagement(manager, mediaPlayerInstance);
Adjustments = new AdjustmentsManagement(manager, mediaPlayerInstance);
}

public string AspectRatio
{
get { return myManager.GetVideoCropGeometry(myMediaPlayer); }
set { myManager.SetVideoCropGeometry(myMediaPlayer, value); }
}

public string CropGeometry
{
Expand Down

0 comments on commit 3768b9d

Please sign in to comment.