Skip to content

Commit a0e300c

Browse files
authored
Merge pull request #34353 from EYHN/eyhn/fix/present-preview-point
Fix present beatmap audio start at the preview point
2 parents 9377ffe + 07137f3 commit a0e300c

File tree

3 files changed

+31
-42
lines changed

3 files changed

+31
-42
lines changed

osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -697,44 +697,6 @@ public void TestDeleteScoreAfterPlaying()
697697
AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null);
698698
}
699699

700-
[TestCase(true)]
701-
[TestCase(false)]
702-
public void TestSongContinuesAfterExitPlayer(bool withUserPause)
703-
{
704-
Player player = null;
705-
706-
IWorkingBeatmap beatmap() => Game.Beatmap.Value;
707-
708-
Screens.SelectV2.SongSelect songSelect = null;
709-
PushAndConfirm(() => songSelect = new SoloSongSelect());
710-
AddUntilStep("wait for song select", () => songSelect.CarouselItemsPresented);
711-
712-
AddStep("import beatmap", () => BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true).WaitSafely());
713-
714-
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
715-
716-
if (withUserPause)
717-
AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop(true));
718-
719-
AddStep("press enter", () => InputManager.Key(Key.Enter));
720-
721-
AddUntilStep("wait for player", () =>
722-
{
723-
DismissAnyNotifications();
724-
return (player = Game.ScreenStack.CurrentScreen as Player) != null;
725-
});
726-
727-
AddUntilStep("wait for fail", () => player.GameplayState.HasFailed);
728-
729-
AddUntilStep("wait for track stop", () => !Game.MusicController.IsPlaying);
730-
AddAssert("Ensure time before preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);
731-
732-
pushEscape();
733-
734-
AddUntilStep("wait for track playing", () => Game.MusicController.IsPlaying);
735-
AddAssert("Ensure time wasn't reset to preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);
736-
}
737-
738700
[Test]
739701
public void TestMenuMakesMusic()
740702
{

osu.Game.Tests/Visual/Navigation/TestSceneSongSelectNavigation.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ public void TestEditBeatmap()
9292
waitForScreen<SoloSongSelect>();
9393
}
9494

95+
[Test]
96+
public void TestPresentBeatmapFromMainMenuUsesPreviewPoint()
97+
{
98+
BeatmapSetInfo beatmapInfo = null!;
99+
100+
AddStep("import beatmap", () =>
101+
{
102+
var task = BeatmapImportHelper.LoadOszIntoOsu(Game, virtualTrack: true);
103+
task.WaitSafely();
104+
beatmapInfo = task.GetResultSafely();
105+
});
106+
107+
AddStep("present beatmap", () => Game.PresentBeatmap(beatmapInfo));
108+
109+
AddUntilStep("wait for track playing", () => Game.MusicController.IsPlaying);
110+
111+
AddAssert("ensure time is reset to preview point",
112+
() =>
113+
{
114+
double timeFromPreviewPoint = Math.Abs(Game.MusicController.CurrentTrack.CurrentTime - beatmapInfo.Metadata.PreviewTime);
115+
return timeFromPreviewPoint < 5000;
116+
});
117+
}
118+
95119
[TestCase(true)]
96120
[TestCase(false)]
97121
public void TestSongContinuesAfterExitPlayer(bool withUserPause)

osu.Game/Screens/SelectV2/SongSelect.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected override void LoadComplete()
346346

347347
ensureGlobalBeatmapValid();
348348

349-
ensurePlayingSelected(true);
349+
ensurePlayingSelected();
350350
updateBackgroundDim();
351351
updateWedgeVisibility();
352352
});
@@ -379,7 +379,7 @@ protected override void Update()
379379
/// Ensures some music is playing for the current track.
380380
/// Will resume playback from a manual user pause if the track has changed.
381381
/// </summary>
382-
private void ensurePlayingSelected(bool restart)
382+
private void ensurePlayingSelected()
383383
{
384384
if (!ControlGlobalMusic)
385385
return;
@@ -391,7 +391,10 @@ private void ensurePlayingSelected(bool restart)
391391
if (!track.IsRunning && (music.UserPauseRequested != true || isNewTrack))
392392
{
393393
Logger.Log($"Song select decided to {nameof(ensurePlayingSelected)}");
394-
music.Play(restart);
394+
395+
// Only restart playback if a new track.
396+
// This is important so that when exiting gameplay, the track is not restarted back to the preview point.
397+
music.Play(isNewTrack);
395398
}
396399

397400
lastTrack.SetTarget(track);
@@ -634,7 +637,7 @@ private void onArrivingAtScreen()
634637

635638
ensureGlobalBeatmapValid();
636639

637-
ensurePlayingSelected(false);
640+
ensurePlayingSelected();
638641
updateBackgroundDim();
639642
}
640643

0 commit comments

Comments
 (0)