How do I get libvlc_media_player_get_time() to return a more accurate result?
Asked Answered
T

1

9

With libvlc, how do I get libvlc_media_player_get_time() to return a more accurate result? With 60fps video the value it returns is only updated a few times per second at most. Is there any way to get frame accurate timing?

Te answered 28/6, 2012 at 0:7 Comment(1)
I'm having an issue with this now because the player I'm building is made for playing short videos (< 1 min in length) and the slow time updates make the position indicator look sluggish and choppy. It's depressing that there is no real solution for this.Triceps
G
11

This issue says that there is no way to get more accurate result from libvlc.

But you can interpolate it:

private long lastPlayTime = 0;
private long lastPlayTimeGlobal = 0;

 /**
 * Get current play time (interpolated)
 * @see https://github.com/caprica/vlcj/issues/74
 * @return
 */
public float getCurrentTime(){
    long currentTime = directMediaPlayer.getTime();

    if (lastPlayTime == currentTime && lastPlayTime != 0){
        currentTime += System.currentTimeMillis() - lastPlayTimeGlobal;
    } else {
        lastPlayTime = currentTime;
        lastPlayTimeGlobal = System.currentTimeMillis();
    }

    return currentTime * 0.001f;    //to float
}
Garboard answered 7/12, 2013 at 7:15 Comment(1)
great, this is awesome solutionExplosion

© 2022 - 2024 — McMap. All rights reserved.