Skip to content

Commit

Permalink
Return negative position when there is no track
Browse files Browse the repository at this point in the history
Also coerce position up to the length
  • Loading branch information
freyacodes committed Oct 9, 2023
1 parent 4e45193 commit 7b52135
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ internal class WebsocketPlayer(internal val node: NodeImpl, internal val guildId
private var updateTime: Instant = Instant.DISTANT_PAST
override val positionDuration: Duration
get() {
val trackLength = playingTrack?.info?.length?.milliseconds ?: return (-1).milliseconds
val now = Clock.System.now()
val elapsedSinceUpdate = now - updateTime

return lastPosition + elapsedSinceUpdate
return (lastPosition + elapsedSinceUpdate).coerceAtMost(trackLength)
}

override val volume: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import kotlin.time.DurationUnit
* @property playingTrack the currently playing [Track]
* @property paused whether the playback is currently paused or not
* @property volume the current volume of this player
* @property position the position of the current song the player is at (-1 if [playingTrack] is null)
* @property positionDuration the position of the current song the player is at (-1 if [playingTrack] is null)
* @property position the position of the current song the player is at (or negative if [playingTrack] is null).
* Capped at the track length.
* @property positionDuration the position of the current song the player is at (or negative if [playingTrack] is null).
* Capped at the track length.
* @property equalizers the applied equalizers in this player
*/
public interface Player : EventSource<Event> {
Expand Down

0 comments on commit 7b52135

Please sign in to comment.