mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 22:33:05 +08:00
Merge pull request #4846 from peppy/fix-preview-state
Fix audio preview buttons not correctly handling load failure states
This commit is contained in:
commit
48ef1ae200
@ -28,7 +28,8 @@ namespace osu.Game.Audio
|
||||
private void load()
|
||||
{
|
||||
track = GetTrack();
|
||||
track.Completed += () => Schedule(Stop);
|
||||
if (track != null)
|
||||
track.Completed += () => Schedule(Stop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -56,19 +57,25 @@ namespace osu.Game.Audio
|
||||
/// <summary>
|
||||
/// Starts playing this <see cref="PreviewTrack"/>.
|
||||
/// </summary>
|
||||
public void Start() => startDelegate = Schedule(() =>
|
||||
/// <returns>Whether the track is started or already playing.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops playing this <see cref="PreviewTrack"/>.
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user