0

My code is:

    public Form1()
    {
        InitializeComponent();

        Core.Initialize();
        this.KeyPreview = true;
        this.KeyDown += new KeyEventHandler(ShortcutEvent);
        oldVideoSize = videoView1.Size;
        oldFormSize = this.Size;
        oldVideoLocation = videoView1.Location;
        //VLC stuff
        _libVLC = new LibVLC();
        _mp = new MediaPlayer(_libVLC);
        videoView1.MediaPlayer = _mp;

        timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        TimeSpan Percent = TimeSpan.FromSeconds(_mp.Position);
        label1.Text = Percent.ToString(@"hh\:mm\:ss");

        TimeSpan time = TimeSpan.FromSeconds(_mp.Time);
        label2.Text = time.ToString(@"hh\:mm\:ss");

        TimeSpan length = TimeSpan.FromSeconds(_mp.Length);
        label3.Text = length.ToString(@"hh\:mm\:ss");
    }

The percentage part doesn't work at all, and the current time part doesn't run correctly and doesn't tick in a real clock but according to an illogical division, and the return of the total time of the video doesn't make sense in its conversion to the clock string.

It seems that the conversion doesn't fit here, or there is another code or an alternative, so I'm asking someone who has something that returns what I'm looking for, that is, how long the video actually is, and where it is now, in a way that looks like a clock, that is: .ToString(@"hh\ :mm:ss").

Thank you!

1 Answers1

0

I know this is a little late, but your last question wasn't answered yet. As mentioned in the comments you need to use milliseconds instead of seconds.

So, for your example above you would just need to change the TimeSpan method used like so

private void timer1_Tick(object sender, EventArgs e)
{
    TimeSpan time = TimeSpan.FromMilliseconds(_mp.Time);
    label2.Text = time.ToString(@"hh\:mm\:ss");

    TimeSpan length = TimeSpan.FromMilliseconds(_mp.Length);
    label3.Text = length.ToString(@"hh\:mm\:ss");
}

I've removed the position label because that is just a float that will be 0 to 1 so not useful in the TimeSpan.

Skint007
  • 195
  • 5
  • 15