Skip to content

Commit

Permalink
Merge pull request #29 from botlabs-gg/duration-timing
Browse files Browse the repository at this point in the history
Return negative position when there is no track
  • Loading branch information
DRSchlaubi committed Oct 10, 2023
2 parents 4e45193 + f5127ed commit dc88890
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 dc88890

Please sign in to comment.