diff --git a/src/music_box.rs b/src/music_box.rs index ec023cd4fbaa131093c639eca2f25c602968ab92..3c27cf40ab9ccaffd1febed5d80a99eac6d647d7 100644 --- a/src/music_box.rs +++ b/src/music_box.rs @@ -352,6 +352,43 @@ impl<'w, 's, T: SuppliesAudio> MusicBox<'w, 's, T> { self.settings.ui_volume = level; } + /// Stop an audio instance handle from playing immediately + pub fn stop_handle(&mut self, handle: &Handle<AudioInstance>) { + if let Some(instance) = self.audio_instances.get_mut(handle) { + instance.stop(AudioTween::default()); + } + } + /// Stop an audio instance handle from playing with a given tween + pub fn stop_handle_with_tween(&mut self, handle: &Handle<AudioInstance>, tween: AudioTween) { + if let Some(instance) = self.audio_instances.get_mut(handle) { + instance.stop(tween); + } + } + /// Pause an audio instance handle immediately, in a way that can be resumed later + pub fn pause_handle(&mut self, handle: &Handle<AudioInstance>) { + if let Some(instance) = self.audio_instances.get_mut(handle) { + instance.pause(AudioTween::default()); + } + } + /// Pause an audio instance with a given tween in a way that can be resumed later + pub fn pause_handle_with_tween(&mut self, handle: &Handle<AudioInstance>, tween: AudioTween) { + if let Some(instance) = self.audio_instances.get_mut(handle) { + instance.pause(tween); + } + } + /// Stop an audio instance handle from playing immediately + pub fn resume_handle(&mut self, handle: &Handle<AudioInstance>) { + if let Some(instance) = self.audio_instances.get_mut(handle) { + instance.resume(AudioTween::default()); + } + } + /// Stop an audio instance handle from playing with a given tween + pub fn resume_handle_with_tween(&mut self, handle: &Handle<AudioInstance>, tween: AudioTween) { + if let Some(instance) = self.audio_instances.get_mut(handle) { + instance.resume(tween); + } + } + fn map_tracks<Name: ToString>(&'w self, name: Name) -> TrackType<Handle<AudioSource>> { match self.handles.resolve_track_name(name) { TrackType::Single(name) => match self.handles.get_audio_track(name) {