Page 1 of 1

libvlc and setting time/position

Posted: 18 Mar 2007 05:20
by simontam
I'm using nativeVlc.cs (C#) to access libvlc. I have a video that I want to start playback at X amount of time into the video.

For some reason the code I have here works but only after you have begun playing the video once. The first time you play the video it starts at the very beginning. Subsequent calls adhere to the time setting and video playback begins at the time specified. Any ideas what's wrong? Also note that if I use Play(item) it completely ignores the time altogether.


if (textBox1.Text != "")
{
this.nativeVlc.Time = Convert.ToInt32(textBox1.Text);
}
this.nativeVlc.AddTarget("c:\\temp\\foo.mpg", null, ref item);
//this.nativeVlc.Play(item);
this.nativeVlc.Play();

Posted: 22 Mar 2007 00:59
by Tappen
VLC doesn't know how long an item is, or how to seek within it, till it's started. You have to wait till you see the status is playing before you can set the time. Vlc is multi-threaded, so it's an asynchronous thing you have to poll for.

You can try using a parameter in the AddTarget call:

"--start-time=" + Convert.ToInt32(textBox1.Text)

or maybe

":start-time=" + Convert.ToInt32(textBox1.Text)

I'm never sure whether -- or : is more likely to work in parameters when scripting. This should work for playing an .mpg file on the hard-disk but I know this parameter won't work for DVD tracks.

Posted: 22 Mar 2007 13:24
by Spellcoder
With the Mozilla plugin/Javascript I have no problem in using :start-time with DVD's in the options with 0.8.6 and 0.9.0. (I use dvdread:// as protocol to play DVD).

I can't imagine it should make a difference whether you use it in the Mozilla plugin or ActiveX with C#, because the options are parsed by VLC.

One thing you have to look out for though is that :start-time works with seconds, while the seeking methods use the time in milliseconds.