Skip to content

Commit

Permalink
Add Video Aspect Ratio Combox To Winform Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
microchi committed Mar 16, 2016
1 parent e974637 commit 10d9af4
Show file tree
Hide file tree
Showing 3 changed files with 85 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>

0 comments on commit 10d9af4

Please sign in to comment.