Skip to content

Commit

Permalink
Allow getting the player's seek time instead of the real time
Browse files Browse the repository at this point in the history
  • Loading branch information
iscle committed Feb 8, 2022
1 parent 58defc7 commit 2050c6a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions player/src/main/java/xyz/gianlu/librespot/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,17 @@ public int time() {
}
}

/**
* @return The current seek position of the player or {@code -1} if unavailable (most likely if it's playing an episode).
*/
public int seekTime() {
try {
return playerSession == null ? -1 : playerSession.currentSeekTime();
} catch (Decoder.CannotGetTimeException ex) {
return -1;
}
}


// ================================ //
// ============ Close! ============ //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ int getTime() throws Decoder.CannotGetTimeException {
return decoder == null ? -1 : decoder.time();
}

/**
* Returns the current seek position. This might not be the real player position if it's called right after a seek.
*
* @return The current seek position of the player or {@code -1} if not ready.
* @throws Decoder.CannotGetTimeException If the time is unavailable for the codec being used.
*/
int getSeekTime() throws Decoder.CannotGetTimeException {
int seekTime = this.seekTime;
if (seekTime != -1) return seekTime;
if (decoder != null) return decoder.time();
return -1;
}

/**
* Returns the current position.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ public int currentTime() throws Decoder.CannotGetTimeException {
else return queue.head().getTime();
}

/**
* @return The seek time for the current head or {@code -1} if not available.
* @throws Decoder.CannotGetTimeException If the head is available, but time cannot be retrieved
*/
public int currentSeekTime() throws Decoder.CannotGetTimeException {
if (queue.head() == null) return -1;
else return queue.head().getSeekTime();
}

@Nullable
public String currentPlaybackId() {
if (queue.head() == null) return null;
Expand Down

0 comments on commit 2050c6a

Please sign in to comment.