diff --git a/osu.Game/Audio/PreviewTrack.cs b/osu.Game/Audio/PreviewTrack.cs index 3b21bdefc4..22ce7d4711 100644 --- a/osu.Game/Audio/PreviewTrack.cs +++ b/osu.Game/Audio/PreviewTrack.cs @@ -28,7 +28,8 @@ namespace osu.Game.Audio private void load() { track = GetTrack(); - track.Completed += () => Schedule(Stop); + if (track != null) + track.Completed += () => Schedule(Stop); } /// @@ -56,19 +57,25 @@ namespace osu.Game.Audio /// /// Starts playing this . /// - public void Start() => startDelegate = Schedule(() => + /// Whether the track is started or already playing. + public bool Start() { if (track == null) - return; + return false; - if (hasStarted) - return; + startDelegate = Schedule(() => + { + if (hasStarted) + return; - hasStarted = true; + hasStarted = true; - track.Restart(); - Started?.Invoke(); - }); + track.Restart(); + Started?.Invoke(); + }); + + return true; + } /// /// Stops playing this . diff --git a/osu.Game/Overlays/Direct/PlayButton.cs b/osu.Game/Overlays/Direct/PlayButton.cs index 6daebb3c15..2a77e7ca26 100644 --- a/osu.Game/Overlays/Direct/PlayButton.cs +++ b/osu.Game/Overlays/Direct/PlayButton.cs @@ -129,7 +129,7 @@ namespace osu.Game.Overlays.Direct if (Preview != null) { - Preview.Start(); + attemptStart(); return; } @@ -147,7 +147,7 @@ namespace osu.Game.Overlays.Direct // user may have changed their mind. if (Playing.Value) - preview.Start(); + attemptStart(); }); } else @@ -157,6 +157,12 @@ namespace osu.Game.Overlays.Direct } } + private void attemptStart() + { + if (Preview?.Start() != true) + Playing.Value = false; + } + protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing);