8

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?

Roland Rabien
  • 8,750
  • 7
  • 50
  • 67
  • 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. – arjabbar Mar 30 '16 at 02:13

1 Answers1

10

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
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Dimmduh
  • 803
  • 1
  • 11
  • 18