I successfully finish, thank you it was a good practice for me. I've added the media in formdeneme() method
You have to make public the object which is in VlcControl.cs class.(private VlcMediaPlayer myVlcMediaPlayer;){Very important}
public int a = 0 ;`
public int c = 0;
public delegate void UpdateControlsDelegate(); //Execute when video loads
public formdeneme()
{
InitializeComponent();
myVlcControl.Play("file:///C:/Users/1315k/Downloads/machine.mp4");
// You can add your media like above.
//Event handler for 'current media time' label
this.vlcControl1.PositionChanged += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerPositionChangedEventArgs>(this.vlcControl1_PositionChanged);
//Event handler for setting trackBar1.Maximum on media load
vlcControl1.Playing += new System.EventHandler<VlcMediaPlayerPlayingEventArgs>(SetProgresMax);
}
// This is the main function which you looking.
private void trackBar1_Scroll(object sender, EventArgs e)
{
myVlcControl.myVlcMediaPlayer.Time = trackBar1.Value * 1000;
int b = (int)myVlcControl.myVlcMediaPlayer.Time / 1000;
int d = b / 60;
b = b - d * 60;
label1.Text = d+":"+b + "/"+ c + ":" + a;
// The Time value is milisecond, you have divide 1000 for be second.
}
private void formdeneme_Load(object sender, EventArgs e)
{
a = (int)myVlcControl.myVlcMediaPlayer.Length / 1000;
trackBar1.Maximum = a;
c = a / 60;
a = a - c * 60;
label1.Text = 0 + "/" + c+":"+a;
}
You can add a button that can change media and trackbar.Maximum value.
UPDATED
Thanks to askepott
He added some codes below, I didn't try but Looks good to me.
In order to have a label that displays the current media time, add this delegate function, it's called function (currentTrackTime) below and declaration at the top of this post. Also, don't forget to add the vlcControl1_PositionChanged event handler at the top.
//Update current video time label (delegate)
public void InvokeUpdateControls()
{
if (this.InvokeRequired)
{
this.Invoke(new UpdateControlsDelegate(currentTrackTime));
}
else
{
currentTrackTime();
}
}
//Update current video time label
private void currentTrackTime()
{
int b = (int)vlcControl1.VlcMediaPlayer.Time / 1000;
int d = b / 60;
b = b - d * 60;
label1.Text = d+":"+b + "/"+ c + ":" + a; //min : sec /
}
//Add this to currentTrackTime() if you want your trackbar to automatically update it's value based on current media position
trackBar1.Value = b;
//Invoke update controls on video position change
private void vlcControl1_PositionChanged(object sender, Vlc.DotNet.Core.VlcMediaPlayerPositionChangedEventArgs e)
{
InvokeUpdateControls();
}
//Furthermore, in case you have trouble getting and setting the vlcControl1.Length when loading the video, use this:
//Fire event when the video starts
private void SetProgresMax(object sender, VlcMediaPlayerPlayingEventArgs e)
{
Invoke(new Action(() =>
{
trackBar1.Value = trackBar1.Minimum;
var vlc = (VlcControl)sender;
trackBar1.Maximum = (int)vlc.Length / 1000;
a = (int)vlc.Length / 1000; // Length (s)
c = a / 60; // Length (m)
a = a % 60; // Length (s)
label1.Text = 0 + "/" + c+":"+a;
}));