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

Option to await until a TrackHandle is finished playing #148

Open
Sir-Photch opened this issue Sep 1, 2022 · 3 comments
Open

Option to await until a TrackHandle is finished playing #148

Sir-Photch opened this issue Sep 1, 2022 · 3 comments
Labels
events Relates to driver event handling/generation. feature-request Request for addition of a new feature or improvement. tracks Relates to audio control, state, or lifecycle management.

Comments

@Sir-Photch
Copy link

I suggest adding some way for TrackHandle returned by Driver.play_source() to be awaited, for the future to be finished when the played input is finished.

I have this implemented the following way:

let (call, result) = manager.join( .... ).await;
let player = call.lock().await.play_source(....);
if let Some(duration) = player.metadata().duration {
    tokio::time::sleep(duration).await;
}

Maybe this is something that would be of use for the API?

@FelixMcFelix FelixMcFelix added events Relates to driver event handling/generation. tracks Relates to audio control, state, or lifecycle management. feature-request Request for addition of a new feature or improvement. labels Sep 1, 2022
@FelixMcFelix
Copy link
Member

The correct way to do something like this is to use the existing event system: have a look at the queue implementation to get a feel for how tracks can handle an event on end.

I think a utility function that makes use of this might be useful though, if a little tough to get right ergonomically. I.e., you want to register events before you play a track to ensure no Ends can be missed (though this should only be possible on 0--20ms sources), but naturally you have to play it after registering the event!

@Sir-Photch
Copy link
Author

I see. I am not sure though, if this applies to my usecase.

I think a utility function that makes use of this might be useful though, if a little tough to get right ergonomically.

Well, what if .play_source() returns a tuple consisting of the player as well as some handle that can be joined? Then, the events could be registered internally, before the actual process of playing the input starts.

@FelixMcFelix
Copy link
Member

Well, what if .play_source() returns a tuple...

The problem with doing this is that every single user now pays for an extra event registration, channel allocation, etc. – it isn't zero-cost, regardless of whether they use the feature or not. So this is unlikely to happen.

You could also attach a global event handler to the End event, and simply store a one-shot channel for each needed UUID. All you need to do is await a response on the channel to get the same semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
events Relates to driver event handling/generation. feature-request Request for addition of a new feature or improvement. tracks Relates to audio control, state, or lifecycle management.
Projects
None yet
Development

No branches or pull requests

2 participants