[GH-ISSUE #17] Provide more/better event hooks #5

Closed
opened 2026-02-27 19:28:14 +03:00 by kerem · 5 comments
Owner

Originally created by @michaelherger on GitHub (Jan 29, 2018).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/17

librespot does provide runtime parameters to trigger an external script on some events. I'd like to see this expanded to support native events in the library code. Plus more events than start/stop/change. Eg. a track skip, volume change etc. are not supported at this point.

Background: my main interest currently is Spotify on Squeezebox/Logitech Media Server (LMS). Integration with this environment isn't trivial, as audio data isn't fed to the player hardware, but would go through LMS, then over the network to the players. In order to keep the player UI up to date and in sync with the actual playback, I need to know about changes.

The users of this plugin run LMS on all kinds of platforms, from Windows, over Mac, to various NAS devices, Raspberry Pi, desktop Linux and even FreeBSD. Scripting these platforms in a generic and reliable way is difficult. I therefore forked librespot to add hooks in place of the above which would trigger http requests to LMS. While this works pretty well, it's a hack. I added code mostly to the player.rs code, but would be happy to get back to plain librespot code...

Originally created by @michaelherger on GitHub (Jan 29, 2018). Original GitHub issue: https://github.com/librespot-org/librespot/issues/17 librespot does provide runtime parameters to trigger an external script on some events. I'd like to see this expanded to support native events in the library code. Plus more events than start/stop/change. Eg. a track skip, volume change etc. are not supported at this point. Background: my main interest currently is Spotify on Squeezebox/[Logitech Media Server (LMS).](https://github.com/Logitech/slimserver) Integration with this environment isn't trivial, as audio data isn't fed to the player hardware, but would go through LMS, then over the network to the players. In order to keep the player UI up to date and in sync with the actual playback, I need to know about changes. The users of this plugin run LMS on all kinds of platforms, from Windows, over Mac, to various NAS devices, [Raspberry Pi](http://picoreplayer.sourceforge.net/main_about.shtml), desktop Linux and even FreeBSD. Scripting these platforms in a generic and reliable way is difficult. [I therefore forked librespot to add hooks](https://github.com/michaelherger/librespot/commit/9a8214340646dbd270cee3b91361b08abeeaa6d5) in place of the above which would trigger http requests to LMS. While this works pretty well, it's a hack. I added code mostly to the player.rs code, but would be happy to get back to plain librespot code...
kerem 2026-02-27 19:28:14 +03:00
Author
Owner

@michaelherger commented on GitHub (Jan 29, 2018):

Related to issue #25

<!-- gh-comment-id:361261895 --> @michaelherger commented on GitHub (Jan 29, 2018): Related to issue #25
Author
Owner

@sashahilton00 commented on GitHub (Feb 1, 2018):

Probably best implemented in #20

<!-- gh-comment-id:362129084 --> @sashahilton00 commented on GitHub (Feb 1, 2018): Probably best implemented in #20
Author
Owner

@plietar commented on GitHub (Feb 8, 2018):

It seems like the onstart/onstop/onchange hooks are more or less sufficient for your usecase, unless I am missing something?

What needs to be done is in player.rs switch them into arbitrary closures and move the "execute external program" part to main.rs. This way you'll be able to use your custom code by only patching/writing your own main.rs

<!-- gh-comment-id:363966273 --> @plietar commented on GitHub (Feb 8, 2018): It seems like the onstart/onstop/onchange hooks are more or less sufficient for your usecase, unless I am missing something? What needs to be done is in `player.rs` switch them into arbitrary closures and move the "execute external program" part to `main.rs`. This way you'll be able to use your custom code by only patching/writing your own `main.rs`
Author
Owner

@michaelherger commented on GitHub (Feb 8, 2018):

That's a starting point. But the player state handling is somewhat irritating: if a track plays out (ends) and a new one begins, I'd get a stop event. I was having a hard time trying to figure out from the callee whether the playback really ended or not. But that's probably my convoluted way of using librespot :-).

FWIW: as I'm not using librespot's playback but am piping the PCM stream through LMS, I did add volume change events, too. But that's really a non-standard use case.

<!-- gh-comment-id:364007326 --> @michaelherger commented on GitHub (Feb 8, 2018): That's a starting point. But the player state handling is somewhat irritating: if a track plays out (ends) and a new one begins, I'd get a stop event. I was having a hard time trying to figure out from the callee whether the playback really ended or not. But that's probably my convoluted way of using librespot :-). FWIW: as I'm not using librespot's playback but am piping the PCM stream through LMS, I did add volume change events, too. But that's really a non-standard use case.
Author
Owner

@sashahilton00 commented on GitHub (Mar 22, 2018):

Continued discussion in #189 and being handled in #190. Closing in favour of those.

<!-- gh-comment-id:375158672 --> @sashahilton00 commented on GitHub (Mar 22, 2018): Continued discussion in #189 and being handled in #190. Closing in favour of those.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#5
No description provided.