Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: position value reverted back to lastPosition when paused #88

Closed
SuspiciousLookingOwl opened this issue Nov 30, 2022 · 6 comments
Closed
Assignees
Labels
wontfix This will not be worked on

Comments

@SuspiciousLookingOwl
Copy link
Contributor

SuspiciousLookingOwl commented Nov 30, 2022

Describe the bug

When player.pause() is called, position value reverted back to lastPosition for few milliseconds

To Reproduce

Steps to reproduce the behavior:

// show current position and lastPosition every second
setInterval(() => {
  const { position, lastPosition } = player;
  console.log("tick", { position, lastPosition });
}, 1000);

// log value before pause
console.log("before", {
  position: player.position,
  lastPosition: player.lastPosition,
});

await player.pause();

// log value after paused
console.log("after", {
  position: player.position,
  lastPosition: player.lastPosition,
});

Output:

tick { position: 967, lastPosition: 0 }
tick { position: 1976, lastPosition: 0 }
tick { position: 2986, lastPosition: 0 }
tick { position: 3992, lastPosition: 0 }
tick { position: 4875, lastPosition: 4840 }
before { position: 5286, lastPosition: 4840 }
after { position: 4840, lastPosition: 4840 } // position value reverted back to lastPosition value
tick { position: 5280, lastPosition: 5280 } // fixed here
tick { position: 5280, lastPosition: 5280 }
tick { position: 5280, lastPosition: 5280 }
tick { position: 5280, lastPosition: 5280 }

I have to add some delay before logging after to get the accurate position value

// log value before pause
console.log("before", {
  position: player.position,
  lastPosition: player.lastPosition,
});

await player.pause();
await new Promise((r) => setTimeout(r, 1000));

// log value after paused
console.log("after", {
  position: player.position,
  lastPosition: player.lastPosition,
});

Output:

tick { position: 975, lastPosition: 0 }
tick { position: 1984, lastPosition: 0 }
tick { position: 2999, lastPosition: 0 }
tick { position: 4009, lastPosition: 0 }
before { position: 4806, lastPosition: 0 }
tick { position: 4760, lastPosition: 4760 }
after { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }
tick { position: 4760, lastPosition: 4760 }

Expected behavior

position value shouldn't revert back to lastPosition value when player paused.

Environment

  • nodejs version: v16.16.0
  • lavalink version: 3.7 (docker)
  • lavaclient version: 4.1.1
@SuspiciousLookingOwl SuspiciousLookingOwl added the bug Something isn't working label Nov 30, 2022
@SerenModz21
Copy link
Member

The code provided, is that what you use? Lavaclient's player class does not have an audioPlayer property.

@SuspiciousLookingOwl
Copy link
Contributor Author

SuspiciousLookingOwl commented Nov 30, 2022

Whoops forgot to change it, it's from the code I use, player.audioPlayer is Lavaclient's player (from lavalink.createPlayer(...)), edited.

@SerenModz21
Copy link
Member

could u listen to the debug event and show us what is shown?

@viztea
Copy link
Collaborator

viztea commented Dec 1, 2022

Lavaclient returns lastPosition while paused because the position would appear to advance even though it actually isn't.

return this.paused
? Math.min(lastPosition, length)
: Math.min(lastPosition + (Date.now() - lastUpdate), length);

I could just store when the player is paused but that's quite sloppy imo 🤷🏼

@viztea viztea closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2022
@viztea viztea added wontfix This will not be worked on and removed bug Something isn't working labels Dec 1, 2022
@SuspiciousLookingOwl
Copy link
Contributor Author

SuspiciousLookingOwl commented Dec 1, 2022

Yep I just noticed that after learning more about Lavalink. I have a use case that requires quite accurate position time, so I just decrease the playerUpdateInterval value on Lavalink config which solves my issues. Disregard this issue 😄

@viztea
Copy link
Collaborator

viztea commented Dec 1, 2022

All good :)

@viztea viztea mentioned this issue Mar 14, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants