Search code examples
c#.netlibvlclibvlcsharp

C# LibVLCSharp: Update speed of MediaPlayer.TimeChanged-Event


is there a way to change the update speed of the LibVLCSharp MediaPlayer TimeChanged-Event?

I use this event to update the remaining playtime of my video. But this is too slow for my purpose. I would like to update the remaining time every 10ms. Is that possible?

My Code:


private void InitMediaPlayer()
{
    vlc = new LibVLC(true, "");
    videoClipMediaPlayer = new MediaPlayer(vlc);
    videoClipMediaPlayer.TimeChanged += MediaPlayerTimeChanged;
}


private void MediaPlayerTimeChanged(object sender, MediaPlayerTimeChangedEventArgs e)
{
    long RemainingTimeMS = videoClipMediaPlayer.Media.Duration - e.Time;
    RemainingPlayTime = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(RemainingTimeMS)); 
    
    // this is only called every 250 milliseconds
}


Solution

  • That's not possible to increase the rate of callbacks, because libvlc doesn't let you do that. The events are triggered synchronously on the playback thread, and having callbacks that takes too long would stutter the video.

    Instead, you could have your own timer and interpolate the video's time, and resync the counter at each TimeChanged. You would need to save the vodeo's time along with the current computer time, and in each of your timer's callback, newVideoTime = lastVideoSyncTime + (now - lastSyncTime)