mirror of
https://github.com/librespot-org/librespot.git
synced 2026-04-27 08:15:50 +03:00
[GH-ISSUE #1493] Get current playback position #673
Labels
No labels
A-Alsa
SpotifyAPI
Tokio 1.0
audio
bug
can't reproduce
compilation
dependencies
duplicate
enhancement
good first issue
help wanted
high priority
imported
imported
invalid
new api
pull-request
question
reverse engineering
wiki
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/librespot#673
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fragsalat on GitHub (Apr 28, 2025).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/1493
Hey there, first of all thanks for your great work :)
Is your feature request related to a problem? Please describe.
I would find it helpful, if the Player struct gets a function to retrieve the current playback position in ms. As of now we can control the playback but don't get information about the progress. As the timing for a progress bar using a separate thread with a tokio interval likely diverge from the actual playback progress, it would be helpful to have a way to retrieve the current playback position to correct such a progress bar timer.
Describe the solution you'd like
Describe alternatives you've considered
It would be also sufficient if the
PlayerConfigcould allow a config likenotify_playback_progressand in the player.rs:1334 the progress is constantly notified.Initially I did try to poll the spotify API but it seem like librespot downloads the track and sends the data to the local sink without reporting to spotify the playback status. At least when using the player.load() method.
Additional context
If wanted I could give it a try to implement this.
@photovoltex commented on GitHub (Apr 28, 2025):
I think what you describe already exists here as a channel that sends the events that happen with the player. The same channel can also be retrieved when using the
Spirc:)https://github.com/librespot-org/librespot/blob/dev/playback%2Fsrc%2Fplayer.rs#L547
@fragsalat commented on GitHub (Apr 28, 2025):
Hey, thanks for the fast respone. I did had a look at the PlayerEvent enum and did not find a correct event which is sent for the progress. There is the ProgressCorrection event but this is only sent under certain circumstances [1] like when seeking.
I would like to get the progress constantly or ad-hoc, depending on whats easier to implement. I think a flag to change the behavior and constantly send the PositionCorrection event would be the simplest solution but not backward compatible as this changes the behavior of the event. So a new event in combination with a flag (if we don't want to always send this due to performance constraints or what ever reasons) could solve this.
[1] https://github.com/librespot-org/librespot/blob/dev/playback/src/player.rs#L1300-L1332
@photovoltex commented on GitHub (Apr 28, 2025):
In addition to the
ProgressCorrectionthe position is also send when the playback state changes as theposition_msfield. See:PlayerEvent::LoadingPlayerEvent::PlayingPlayerEvent::PausedPlayerEvent::Seeked@fragsalat commented on GitHub (Apr 28, 2025):
I did create a PR to extend this with a PositionChanged event, which is emitted every 250ms during playback.
By consuming this it is possible to implement a progress bar during playback.
I did not reuse ProgressCorrection as this would not be backward compatible as mentioned before.
@photovoltex commented on GitHub (May 4, 2025):
Huh, the PR didn't seem to have closed the issue. Well whatever. Closing due to #1495 being merged :)