diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableSound.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableSound.cs index cc82ffed2b..3f78dbfd96 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableSound.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableSound.cs @@ -107,15 +107,12 @@ public void TestSampleUpdatedBeforePlaybackWhenNotPresent() AddUntilStep("ensure sample loaded", () => skinnableSound.ChildrenOfType().Single().Name, () => Is.EqualTo(sample_lookup)); - AddStep("Change source", () => + AddStep("change source", () => { skinSource.OverridingSample = new SampleVirtual("new skin"); skinSource.TriggerSourceChanged(); }); - // Samples are nulled on source change immediately - AddUntilStep("wait for sample null", () => skinnableSound.ChildrenOfType().Count(), () => Is.Zero); - AddStep("start sample", () => skinnableSound.Play()); AddUntilStep("sample updated", () => skinnableSound.ChildrenOfType().Single().Name, () => Is.EqualTo("new skin")); } diff --git a/osu.Game/Skinning/PoolableSkinnableSample.cs b/osu.Game/Skinning/PoolableSkinnableSample.cs index 361c8688e7..eacb33f7d7 100644 --- a/osu.Game/Skinning/PoolableSkinnableSample.cs +++ b/osu.Game/Skinning/PoolableSkinnableSample.cs @@ -4,12 +4,10 @@ #nullable disable using System; -using System.Linq; using JetBrains.Annotations; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Audio; using osu.Framework.Graphics.Containers; @@ -70,48 +68,21 @@ public void Apply(ISampleInfo sampleInfo) updateSample(); } - protected override void LoadComplete() - { - base.LoadComplete(); - - CurrentSkin.SourceChanged += skinChangedImmediate; - } - - private void skinChangedImmediate() - { - // Clean up the previous sample immediately on a source change. - // This avoids a potential call to Play() of an already disposed sample (samples are disposed along with the skin, but SkinChanged is scheduled). - clearPreviousSamples(); - } - protected override void SkinChanged(ISkinSource skin) { base.SkinChanged(skin); updateSample(); } - /// - /// Whether this sample was playing before a skin source change. - /// - private bool wasPlaying; - - private void clearPreviousSamples() - { - // only run if the samples aren't already cleared. - // this ensures the "wasPlaying" state is stored correctly even if multiple clear calls are executed. - if (!sampleContainer.Any()) return; - - wasPlaying = Playing; - - sampleContainer.Clear(); - Sample = null; - } - private void updateSample() { if (sampleInfo == null) return; + bool wasPlaying = Playing; + + sampleContainer.Clear(); + var sample = CurrentSkin.GetSample(sampleInfo); if (sample == null) @@ -174,14 +145,6 @@ public bool Looping } } - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - - if (CurrentSkin.IsNotNull()) - CurrentSkin.SourceChanged -= skinChangedImmediate; - } - #region Re-expose AudioContainer public BindableNumber Volume => sampleContainer.Volume;