mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 17:27:48 +08:00
Merge pull request #10694 from peppy/fix-pausable-skinnable-sound-for-the-last-time
Fix paused samples potentially getting stuck in a playing state in rapid toggling
This commit is contained in:
commit
0b683c8c74
@ -4,6 +4,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
@ -25,6 +26,8 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
private readonly IBindable<bool> samplePlaybackDisabled = new Bindable<bool>();
|
private readonly IBindable<bool> samplePlaybackDisabled = new Bindable<bool>();
|
||||||
|
|
||||||
|
private ScheduledDelegate scheduledStart;
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(ISamplePlaybackDisabler samplePlaybackDisabler)
|
private void load(ISamplePlaybackDisabler samplePlaybackDisabler)
|
||||||
{
|
{
|
||||||
@ -39,12 +42,14 @@ namespace osu.Game.Skinning
|
|||||||
// let non-looping samples that have already been started play out to completion (sounds better than abruptly cutting off).
|
// let non-looping samples that have already been started play out to completion (sounds better than abruptly cutting off).
|
||||||
if (!Looping) return;
|
if (!Looping) return;
|
||||||
|
|
||||||
|
cancelPendingStart();
|
||||||
|
|
||||||
if (disabled.NewValue)
|
if (disabled.NewValue)
|
||||||
base.Stop();
|
base.Stop();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// schedule so we don't start playing a sample which is no longer alive.
|
// schedule so we don't start playing a sample which is no longer alive.
|
||||||
Schedule(() =>
|
scheduledStart = Schedule(() =>
|
||||||
{
|
{
|
||||||
if (RequestedPlaying)
|
if (RequestedPlaying)
|
||||||
base.Play();
|
base.Play();
|
||||||
@ -56,6 +61,7 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
public override void Play()
|
public override void Play()
|
||||||
{
|
{
|
||||||
|
cancelPendingStart();
|
||||||
RequestedPlaying = true;
|
RequestedPlaying = true;
|
||||||
|
|
||||||
if (samplePlaybackDisabled.Value)
|
if (samplePlaybackDisabled.Value)
|
||||||
@ -66,8 +72,15 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
{
|
{
|
||||||
|
cancelPendingStart();
|
||||||
RequestedPlaying = false;
|
RequestedPlaying = false;
|
||||||
base.Stop();
|
base.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cancelPendingStart()
|
||||||
|
{
|
||||||
|
scheduledStart?.Cancel();
|
||||||
|
scheduledStart = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user