Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

libvlc

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?

like image 239
Roland Rabien Avatar asked Jun 28 '12 00:06

Roland Rabien


1 Answers

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
}
like image 115
Dimmduh Avatar answered Nov 07 '22 04:11

Dimmduh