Avoid calls on MusicController executing before it may have finished loading

This commit is contained in:
Dean Herbert
2020-04-28 11:46:08 +09:00
parent 48ef9a0484
commit 62be138aa9
2 changed files with 20 additions and 15 deletions

View File

@ -47,18 +47,19 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void TestPrevTrackBehavior() public void TestPrevTrackBehavior()
{ {
AddStep(@"Play track", () => AddStep(@"Next track", () => musicController.NextTrack());
{ AddStep("Store track", () => currentBeatmap = Beatmap.Value);
musicController.NextTrack();
currentBeatmap = Beatmap.Value;
});
AddStep(@"Seek track to 6 second", () => musicController.SeekTo(6000)); AddStep(@"Seek track to 6 second", () => musicController.SeekTo(6000));
AddUntilStep(@"Wait for current time to update", () => currentBeatmap.Track.CurrentTime > 5000); AddUntilStep(@"Wait for current time to update", () => currentBeatmap.Track.CurrentTime > 5000);
AddAssert(@"Check action is restart track", () => musicController.PreviousTrack() == PreviousTrackResult.Restart);
AddUntilStep("Wait for current time to update", () => Precision.AlmostEquals(currentBeatmap.Track.CurrentTime, 0)); AddStep(@"Set previous", () => musicController.PreviousTrack());
AddAssert(@"Check track didn't change", () => currentBeatmap == Beatmap.Value); AddAssert(@"Check track didn't change", () => currentBeatmap == Beatmap.Value);
AddAssert(@"Check action is not restart", () => musicController.PreviousTrack() != PreviousTrackResult.Restart); AddUntilStep("Wait for current time to update", () => currentBeatmap.Track.CurrentTime < 5000);
AddStep(@"Set previous", () => musicController.PreviousTrack());
AddAssert(@"Check track did change", () => currentBeatmap != Beatmap.Value);
} }
} }
} }

View File

@ -172,10 +172,15 @@ namespace osu.Game.Overlays
} }
/// <summary> /// <summary>
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/> /// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
/// </summary> /// </summary>
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action</returns> public void PreviousTrack() => Schedule(() => prev());
public PreviousTrackResult PreviousTrack()
/// <summary>
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
/// </summary>
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action.</returns>
private PreviousTrackResult prev()
{ {
var currentTrackPosition = current?.Track.CurrentTime; var currentTrackPosition = current?.Track.CurrentTime;
@ -204,8 +209,7 @@ namespace osu.Game.Overlays
/// <summary> /// <summary>
/// Play the next random or playlist track. /// Play the next random or playlist track.
/// </summary> /// </summary>
/// <returns>Whether the operation was successful.</returns> public void NextTrack() => Schedule(() => next());
public bool NextTrack() => next();
private bool next(bool instant = false) private bool next(bool instant = false)
{ {
@ -319,13 +323,13 @@ namespace osu.Game.Overlays
return true; return true;
case GlobalAction.MusicNext: case GlobalAction.MusicNext:
if (NextTrack()) if (next())
onScreenDisplay?.Display(new MusicControllerToast("Next track")); onScreenDisplay?.Display(new MusicControllerToast("Next track"));
return true; return true;
case GlobalAction.MusicPrev: case GlobalAction.MusicPrev:
switch (PreviousTrack()) switch (prev())
{ {
case PreviousTrackResult.Restart: case PreviousTrackResult.Restart:
onScreenDisplay?.Display(new MusicControllerToast("Restart track")); onScreenDisplay?.Display(new MusicControllerToast("Restart track"));