audio: Remove AudioBackend::stop_sounds_with_handle/is_sound_playing_with_handle

This commit is contained in:
Mike Welsh 2021-01-24 17:08:25 -08:00
parent da2dd3b36c
commit 95ce2abf17
4 changed files with 3 additions and 39 deletions

View File

@ -535,7 +535,8 @@ fn stop<'gc>(
.character_by_export_name(&name) .character_by_export_name(&name)
{ {
// Stop all sounds with the given name. // Stop all sounds with the given name.
activation.context.audio.stop_sounds_with_handle(*sound); let sound = *sound;
activation.context.stop_sounds_with_handle(sound);
} else { } else {
avm_warn!(activation, "Sound.stop: Sound '{}' not found", name); avm_warn!(activation, "Sound.stop: Sound '{}' not found", name);
} }

View File

@ -69,15 +69,6 @@ pub trait AudioBackend: Downcast {
/// Good ol' stopAllSounds() :-) /// Good ol' stopAllSounds() :-)
fn stop_all_sounds(&mut self); fn stop_all_sounds(&mut self);
/// Stops all active sound instances of a particular sound.
/// Used by SWF `StartSound` tag with `SoundEvent::Stop`.
fn stop_sounds_with_handle(&mut self, handle: SoundHandle);
/// Returns whether a sound clip is playing.
/// Used by SWF `StartSouynd` tag with `SoundEvent:Start`,
/// which only plays a sound if that sound is not already playing.
fn is_sound_playing_with_handle(&mut self, handle: SoundHandle) -> bool;
/// Get the position of a sound instance in milliseconds. /// Get the position of a sound instance in milliseconds.
/// Returns `None` if ther sound is not/no longer playing /// Returns `None` if ther sound is not/no longer playing
fn get_sound_position(&self, instance: SoundInstanceHandle) -> Option<u32>; fn get_sound_position(&self, instance: SoundInstanceHandle) -> Option<u32>;
@ -151,11 +142,6 @@ impl AudioBackend for NullAudioBackend {
self.streams.remove(stream); self.streams.remove(stream);
} }
fn stop_all_sounds(&mut self) {} fn stop_all_sounds(&mut self) {}
fn stop_sounds_with_handle(&mut self, _handle: SoundHandle) {}
fn is_sound_playing_with_handle(&mut self, _handle: SoundHandle) -> bool {
false
}
fn get_sound_position(&self, _instance: SoundInstanceHandle) -> Option<u32> { fn get_sound_position(&self, _instance: SoundInstanceHandle) -> Option<u32> {
None None
} }

View File

@ -424,12 +424,6 @@ impl AudioBackend for CpalAudioBackend {
sound_instances.clear(); sound_instances.clear();
} }
fn stop_sounds_with_handle(&mut self, handle: SoundHandle) {
let mut sound_instances = self.sound_instances.lock().unwrap();
let handle = Some(handle);
sound_instances.retain(|_, instance| instance.handle != handle);
}
fn get_sound_position(&self, instance: SoundInstanceHandle) -> Option<u32> { fn get_sound_position(&self, instance: SoundInstanceHandle) -> Option<u32> {
let sound_instances = self.sound_instances.lock().unwrap(); let sound_instances = self.sound_instances.lock().unwrap();
if let Some(_instance) = sound_instances.get(instance) { if let Some(_instance) = sound_instances.get(instance) {

View File

@ -77,6 +77,7 @@ type Decoder = Box<dyn Iterator<Item = [i16; 2]>>;
/// a stream sound (`SoundStreamBlock`). /// a stream sound (`SoundStreamBlock`).
struct SoundInstance { struct SoundInstance {
/// Handle to the sound clip. /// Handle to the sound clip.
#[allow(dead_code)]
handle: Option<SoundHandle>, handle: Option<SoundHandle>,
/// Format of the sound. /// Format of the sound.
@ -986,24 +987,6 @@ impl AudioBackend for WebAudioBackend {
}) })
} }
fn stop_sounds_with_handle(&mut self, handle: SoundHandle) {
SOUND_INSTANCES.with(|instances| {
let mut instances = instances.borrow_mut();
let handle = Some(handle);
instances.retain(|_, instance| instance.handle != handle);
})
}
fn is_sound_playing_with_handle(&mut self, handle: SoundHandle) -> bool {
SOUND_INSTANCES.with(|instances| {
let instances = instances.borrow();
let handle = Some(handle);
instances
.iter()
.any(|(_, instance)| instance.handle == handle)
})
}
fn get_sound_position(&self, instance: SoundInstanceHandle) -> Option<u32> { fn get_sound_position(&self, instance: SoundInstanceHandle) -> Option<u32> {
SOUND_INSTANCES.with(|instances| { SOUND_INSTANCES.with(|instances| {
let instances = instances.borrow(); let instances = instances.borrow();