-
Notifications
You must be signed in to change notification settings - Fork 241
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
Callback on source end example #651
Comments
Hi! Just came here to ask about something I assume might be similar. I am looking for a way to assign some My current approach is getting Is there a way to do this already, or is it a planned feature? |
OK seems like this works:
It's quite a strange approach to me, since statistics like number of sources added to the sink's queue, are then "wrong", let's say I added 10 actual audio sources, but getting It's possible to live with that and manage the queue separately somewhere of course. But wondering about the reasons you chose to go for this API specifically. Seems more "direct" to have the Sink itself notify of it progressing through its sources, in the "my current source changed (ended, skipped, etc), here's next source if any". |
there is, we really need an example of that (which is what this issue is for) To run a function once a source end you append a second source of type EmptyCallback it takes as argument: Once your first source ends the queue 'plays' emptycallback. It does not make sound but runs your function. Once your function is done the queue immediately moves to the next source. |
lol you found out about the same time as I typed my explanation.
Its an old choice from before my time as maintainer. It does however make things internally easier. We are designing a more high level API to rodio (its probably going to be called If you have time please let us know what you need: #626 |
That would be super useful - I hit exactly the same question. |
Has an explicit comment instructing the user in the use of `move` since thats something people struggle with. I could have made the example nicer and more functional. It could be refactored with a function that generates the callback. Then we would have something like: ```rust fn new_playlist_pos_callback() -> impl Fn() + Send { ... } sink.append(song); sink.append(new_playlist_pos_callback()); sink.append(song); sink.append(new_playlist_pos_callback()); sink.append(song); sink.append(new_playlist_pos_callback()); ``` I chose instead to keep it as short and simple as possible, even though the example code on its own is not as usefull now.
Has an explicit comment instructing the user in the use of `move` since thats something people struggle with. I could have made the example nicer and more functional. It could be refactored with a function that generates the callback. Then we would have something like: ```rust fn new_playlist_pos_callback() -> impl Fn() + Send { ... } sink.append(song); sink.append(new_playlist_pos_callback()); sink.append(song); sink.append(new_playlist_pos_callback()); sink.append(song); sink.append(new_playlist_pos_callback()); ``` I chose instead to keep it as short and simple as possible, even though the example code on its own is not as usefull now. Functions returning a generic boxed closure are hard to understand and that distracts from what we are trying to show here (how to use the emptycallback source).
adds example for emptycallback closing #651
Would have helped with: #600 (see last few messages there)
The text was updated successfully, but these errors were encountered: