librespot-java icon indicating copy to clipboard operation
librespot-java copied to clipboard

Seeking 'Player' does not update player.time() instantly, and there is no way to wait for update

Open vhaudiquet opened this issue 4 years ago • 0 comments

Describe the bug Consider the following code :

private xyz.gianlu.librespot.player.Player spotifyPlayer;

void seek(int t)
{
    spotifyPlayer.seek(t);
    System.out.println("Seek to " + t + ", but player reports " + spotifyPlayer.time());
}

You would expect reported time to be t, but it is not, because there seems to be a delay necessary to seek :

2022-01-08 14:52:57.832 24582-24582/v.blade I/System.out: Seek to 119860, but player reports 5887

This is (to me) a bug ; i suggest the following fixes :

  • Either use an internal variable position that can be updated instantly and report the value of that variable, even if the player has not already done seek to the position (as it requires network time, i understand)
  • Or provide a function like waitReady() to wait for player actualization ; i tried with waitReady() but the player is already in a ready state as it is already playing i think
  • Or provide a way to give a callback to the seek function, for when seek is done

EDIT: I found the event 'onTrackSeeked', which i guess i can work with. I think that "seeked" does not exist in english, the verb is "sought" ? Anyway i still think that the first fix is the best way to go because using the API is really weird without that.

To Reproduce Just use previous code.

Version/Commit librespot-player:1.6.2

vhaudiquet avatar Jan 08 '22 14:01 vhaudiquet