diff --git a/osu.Framework.Tests/Audio/SampleBassTest.cs b/osu.Framework.Tests/Audio/SampleBassTest.cs
index b0f65d0c6f0..ed0155b18e2 100644
--- a/osu.Framework.Tests/Audio/SampleBassTest.cs
+++ b/osu.Framework.Tests/Audio/SampleBassTest.cs
@@ -115,17 +115,5 @@ public void TestPlayingUpdatedAfterInlineStop()
bass.RunOnAudioThread(() => channel.Stop());
Assert.That(channel.Playing, Is.False);
}
-
- [Test]
- public void TestChannelLifetime()
- {
- channel = sample.Play();
- bass.Update();
-
- bass.RunOnAudioThread(() => channel.Stop());
- bass.Update();
-
- Assert.That(channel.IsDisposed, Is.True);
- }
}
}
diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs b/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs
index bee9e3b6f10..50a864c3517 100644
--- a/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs
+++ b/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs
@@ -35,13 +35,12 @@ public void TestPlay()
}
[Test]
- public void TestDoesNotRestart()
+ public void TestChannelLifetime()
{
SampleChannel channel = null;
AddStep("play channel 1 sample", () => channel = sample.Play());
AddUntilStep("wait for channel 1 to end", () => !channel.Playing);
- AddStep("play channel 1 again", () => channel.Play());
int audioFrames = 0;
AddStep("begin tracking audio frames", () =>
@@ -58,7 +57,7 @@ public void TestDoesNotRestart()
});
AddUntilStep("wait for two audio frames", () => audioFrames >= 2);
- AddAssert("channel 1 not playing", () => !channel.Playing);
+ AddAssert("channel 1 disposed", () => channel.IsDisposed);
}
[Test]
diff --git a/osu.Framework/Audio/Sample/SampleChannel.cs b/osu.Framework/Audio/Sample/SampleChannel.cs
index 4659004b377..e3bcef8268b 100644
--- a/osu.Framework/Audio/Sample/SampleChannel.cs
+++ b/osu.Framework/Audio/Sample/SampleChannel.cs
@@ -44,8 +44,6 @@ protected override void UpdateState()
public virtual bool Looping { get; set; }
- public override bool IsAlive => base.IsAlive && Playing;
-
public virtual ChannelAmplitudes CurrentAmplitudes { get; } = ChannelAmplitudes.Empty;
#region Mixing
diff --git a/osu.Framework/Audio/Sample/SampleChannelBass.cs b/osu.Framework/Audio/Sample/SampleChannelBass.cs
index f08f5baa496..b57cba7dc63 100644
--- a/osu.Framework/Audio/Sample/SampleChannelBass.cs
+++ b/osu.Framework/Audio/Sample/SampleChannelBass.cs
@@ -40,6 +40,12 @@ public override bool Playing
///
private volatile bool userRequestedPlay;
+ ///
+ /// true if the user last called .
+ /// false if the user last called or this channel finished playback.
+ ///
+ private volatile bool userRequestedStop;
+
///
/// Whether the playback start has been enqueued.
///
@@ -55,6 +61,8 @@ public override bool Looping
}
}
+ public override bool IsAlive => base.IsAlive && (Playing || userRequestedStop);
+
private bool hasChannel => channel != 0;
public override ChannelAmplitudes CurrentAmplitudes => (bassAmplitudeProcessor ??= new BassAmplitudeProcessor(this)).CurrentAmplitudes;
@@ -99,8 +107,13 @@ protected override void UpdateState()
playing = true;
break;
+ case PlaybackState.Paused when userRequestedStop:
+ playing = false;
+ break;
+
default:
playing = false;
+ userRequestedStop = false;
break;
}
}
@@ -119,6 +132,8 @@ public override void Play()
{
userRequestedPlay = true;
+ userRequestedStop = false;
+
// Pin Playing and IsAlive to true so that the channel isn't killed by the next update. This is only reset after playback is started.
enqueuedPlaybackStart = true;
@@ -138,6 +153,8 @@ public override void Stop()
{
userRequestedPlay = false;
+ userRequestedStop = true;
+
base.Stop();
EnqueueAction(() =>
diff --git a/osu.Framework/Audio/Sample/SampleChannelVirtual.cs b/osu.Framework/Audio/Sample/SampleChannelVirtual.cs
index 1629064ebcb..ef77b5f6c38 100644
--- a/osu.Framework/Audio/Sample/SampleChannelVirtual.cs
+++ b/osu.Framework/Audio/Sample/SampleChannelVirtual.cs
@@ -13,6 +13,8 @@ internal class SampleChannelVirtual : SampleChannel
public override bool Playing => playing;
+ public override bool IsAlive => base.IsAlive && Playing;
+
public SampleChannelVirtual(string name)
: base(name)
{