mirror of
https://github.com/ppy/osu
synced 2025-01-18 12:00:58 +00:00
Avoid calls on MusicController executing before it may have finished loading
This commit is contained in:
parent
48ef9a0484
commit
62be138aa9
@ -47,18 +47,19 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Test]
|
||||
public void TestPrevTrackBehavior()
|
||||
{
|
||||
AddStep(@"Play track", () =>
|
||||
{
|
||||
musicController.NextTrack();
|
||||
currentBeatmap = Beatmap.Value;
|
||||
});
|
||||
AddStep(@"Next track", () => musicController.NextTrack());
|
||||
AddStep("Store track", () => currentBeatmap = Beatmap.Value);
|
||||
|
||||
AddStep(@"Seek track to 6 second", () => musicController.SeekTo(6000));
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,10 +172,15 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action</returns>
|
||||
public PreviousTrackResult PreviousTrack()
|
||||
public void PreviousTrack() => Schedule(() => prev());
|
||||
|
||||
/// <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;
|
||||
|
||||
@ -204,8 +209,7 @@ namespace osu.Game.Overlays
|
||||
/// <summary>
|
||||
/// Play the next random or playlist track.
|
||||
/// </summary>
|
||||
/// <returns>Whether the operation was successful.</returns>
|
||||
public bool NextTrack() => next();
|
||||
public void NextTrack() => Schedule(() => next());
|
||||
|
||||
private bool next(bool instant = false)
|
||||
{
|
||||
@ -319,13 +323,13 @@ namespace osu.Game.Overlays
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicNext:
|
||||
if (NextTrack())
|
||||
if (next())
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Next track"));
|
||||
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicPrev:
|
||||
switch (PreviousTrack())
|
||||
switch (prev())
|
||||
{
|
||||
case PreviousTrackResult.Restart:
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Restart track"));
|
||||
|
Loading…
Reference in New Issue
Block a user