mirror of
https://github.com/ppy/osu.git
synced 2026-06-03 03:20:16 +08:00
Fix audio not correctly continuing on resuming from gameplay
This commit is contained in:
@@ -796,6 +796,14 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
AddWaitStep("wait two frames", 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPushSongSelectAndPressBackButtonImmediatelyV2()
|
||||
{
|
||||
AddStep("push song select", () => Game.ScreenStack.Push(new TestPlaySongSelect()));
|
||||
AddStep("press back button", () => Game.ChildrenOfType<BackButton>().First().Action!.Invoke());
|
||||
AddWaitStep("wait two frames", 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestExitSongSelectWithClick()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.SelectV2;
|
||||
using osu.Game.Tests.Beatmaps.IO;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests copied out of `TestSceneScreenNavigation` which are specific to song select.
|
||||
/// These are for SongSelectV2. Eventually, the tests in the above class should be deleted along with old song select.
|
||||
/// </summary>
|
||||
public class TestSceneSongSelectNavigation : OsuGameTestScene
|
||||
{
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestSongContinuesAfterExitPlayer(bool withUserPause)
|
||||
{
|
||||
Player? player = null;
|
||||
|
||||
IWorkingBeatmap beatmap() => Game.Beatmap.Value;
|
||||
|
||||
PushAndConfirm(() => new SoloSongSelect());
|
||||
|
||||
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
|
||||
|
||||
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
|
||||
|
||||
if (withUserPause)
|
||||
AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop(true));
|
||||
|
||||
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
||||
|
||||
AddUntilStep("wait for player", () =>
|
||||
{
|
||||
DismissAnyNotifications();
|
||||
return (player = Game.ScreenStack.CurrentScreen as Player) != null;
|
||||
});
|
||||
|
||||
AddUntilStep("wait for fail", () => player?.GameplayState.HasFailed, () => Is.True);
|
||||
|
||||
AddUntilStep("wait for track stop", () => !Game.MusicController.IsPlaying);
|
||||
AddAssert("Ensure time before preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);
|
||||
|
||||
pushEscape();
|
||||
|
||||
AddUntilStep("wait for track playing", () => Game.MusicController.IsPlaying);
|
||||
AddAssert("Ensure time wasn't reset to preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);
|
||||
}
|
||||
|
||||
private void pushEscape() =>
|
||||
AddStep("Press escape", () => InputManager.Key(Key.Escape));
|
||||
}
|
||||
}
|
||||
@@ -306,14 +306,10 @@ namespace osu.Game.Screens.SelectV2
|
||||
Beatmap.BindValueChanged(_ =>
|
||||
{
|
||||
ensureGlobalBeatmapValid();
|
||||
updateStateFromCurrentBeatmap();
|
||||
});
|
||||
}
|
||||
|
||||
private void updateStateFromCurrentBeatmap()
|
||||
{
|
||||
ensurePlayingSelected();
|
||||
updateBackgroundDim();
|
||||
ensurePlayingSelected(true);
|
||||
updateBackgroundDim();
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@@ -334,7 +330,7 @@ namespace osu.Game.Screens.SelectV2
|
||||
/// Ensures some music is playing for the current track.
|
||||
/// Will resume playback from a manual user pause if the track has changed.
|
||||
/// </summary>
|
||||
private void ensurePlayingSelected()
|
||||
private void ensurePlayingSelected(bool restart)
|
||||
{
|
||||
if (!ControlGlobalMusic)
|
||||
return;
|
||||
@@ -346,7 +342,7 @@ namespace osu.Game.Screens.SelectV2
|
||||
if (!track.IsRunning && (music.UserPauseRequested != true || isNewTrack))
|
||||
{
|
||||
Logger.Log($"Song select decided to {nameof(ensurePlayingSelected)}");
|
||||
music.Play(true);
|
||||
music.Play(restart);
|
||||
}
|
||||
|
||||
lastTrack.SetTarget(track);
|
||||
@@ -518,6 +514,14 @@ namespace osu.Game.Screens.SelectV2
|
||||
|
||||
this.FadeIn(fade_duration, Easing.OutQuint);
|
||||
onArrivingAtScreen();
|
||||
|
||||
if (ControlGlobalMusic)
|
||||
{
|
||||
// restart playback on returning to song select, regardless.
|
||||
// not sure this should be a permanent thing (we may want to leave a user pause paused even on returning)
|
||||
music.ResetTrackAdjustments();
|
||||
music.Play(requestedByUser: true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSuspending(ScreenTransitionEvent e)
|
||||
@@ -556,7 +560,8 @@ namespace osu.Game.Screens.SelectV2
|
||||
|
||||
ensureGlobalBeatmapValid();
|
||||
|
||||
updateStateFromCurrentBeatmap();
|
||||
ensurePlayingSelected(false);
|
||||
updateBackgroundDim();
|
||||
}
|
||||
|
||||
private void onLeavingScreen()
|
||||
|
||||
Reference in New Issue
Block a user