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

Create an example for how to stop a sound. #17

Closed
wainwrightmark opened this issue Aug 22, 2022 · 2 comments · Fixed by #50
Closed

Create an example for how to stop a sound. #17

wainwrightmark opened this issue Aug 22, 2022 · 2 comments · Fixed by #50
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Milestone

Comments

@wainwrightmark
Copy link

Using the latest in main, I'm creating a sound with

let handles = audio.play(noise, sine::Settings::new(0.0, 440.));
commands.insert_resource(SineSink(handles.0, handles.1));

I can't figure out how to stop the sound. I've tried remove the resources and assets and manually dropping them but nothing worked.
It would be great to have an example to see how to do this.

@wainwrightmark
Copy link
Author

I figured it out!

pub fn stop_sine(
    handles: (Handle<AudioHandle<Sine>>, Handle<AudioSink<Sine>>),
    audio_handles: &mut ResMut<Assets<AudioHandle<Sine>>>,
    audio_sinks: &mut ResMut<Assets<AudioSink<Sine>>>,
) {
    audio_handles.remove(handles.0);

    if let Some(mut audio_sink) = audio_sinks.remove(handles.1) {
        audio_sink.control::<oddio::Stop<_>, _>().stop();
    }
}

Happy to make this into an example if you like.

@harudagondi harudagondi added documentation Improvements or additions to documentation good first issue Good for newcomers labels Aug 24, 2022
@harudagondi
Copy link
Owner

Yes, more examples are welcome :)

@harudagondi harudagondi added this to the 0.3 milestone Sep 4, 2022
harudagondi added a commit that referenced this issue Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants