diff --git a/Content.Client/GameObjects/Components/Sound/SoundComponent.cs b/Content.Client/GameObjects/Components/Sound/SoundComponent.cs index c36f79fe83..076ac902a6 100644 --- a/Content.Client/GameObjects/Components/Sound/SoundComponent.cs +++ b/Content.Client/GameObjects/Components/Sound/SoundComponent.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Linq; using Content.Shared.GameObjects.Components.Sound; +using Microsoft.DiaSymReader; using Robust.Client.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; @@ -15,7 +17,7 @@ namespace Content.Client.GameObjects.Components.Sound [RegisterComponent] public class SoundComponent : SharedSoundComponent { - private readonly List _schedules = new List(); + private readonly Dictionary _audioStreams = new Dictionary(); private AudioSystem _audioSystem; #pragma warning disable 649 [Dependency] private readonly IRobustRandom _random; @@ -23,26 +25,27 @@ namespace Content.Client.GameObjects.Components.Sound public override void StopAllSounds() { - foreach (var schedule in _schedules) + foreach (var kvp in _audioStreams) { - schedule.Play = false; + kvp.Key.Play = false; + kvp.Value.Stop(); } - _schedules.Clear(); + _audioStreams.Clear(); } public override void StopScheduledSound(string filename) { - foreach (var schedule in _schedules.ToArray()) + foreach (var kvp in _audioStreams) { - if (schedule.Filename != filename) continue; - schedule.Play = false; - _schedules.Remove(schedule); + if (kvp.Key.Filename != filename) continue; + kvp.Key.Play = false; + kvp.Value.Stop(); + _audioStreams.Remove(kvp.Key); } } public override void AddScheduledSound(ScheduledSound schedule) { - _schedules.Add(schedule); Play(schedule); } @@ -54,16 +57,11 @@ namespace Content.Client.GameObjects.Components.Sound { if (!schedule.Play) return; // We make sure this hasn't changed. if (_audioSystem == null) _audioSystem = IoCManager.Resolve().GetEntitySystem(); - _audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams); + _audioStreams.Add(schedule,_audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams)); - if (schedule.Times == 0) - { - _schedules.Remove(schedule); - return; - } + if (schedule.Times == 0) return; - if (schedule.Times > 0) - schedule.Times--; + if (schedule.Times > 0) schedule.Times--; Play(schedule); });