From 941e8525af5c1b26b5aadc6ffd52554b53f2cf4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 31 Oct 2020 16:06:53 +0100 Subject: [PATCH 1/5] Add flag parameter to allow non-user-pause via music controller --- osu.Game/Overlays/MusicController.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 12caf98021..7e7be31de6 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -182,9 +182,14 @@ namespace osu.Game.Overlays /// /// Stop playing the current track and pause at the current position. /// - public void Stop() + /// + /// Whether the request to stop was issued by the user rather than internally. + /// Specifying true will ensure that other methods like + /// will not resume music playback until the next explicit call to . + /// + public void Stop(bool requestedByUser = true) { - IsUserPaused = true; + IsUserPaused |= requestedByUser; if (CurrentTrack.IsRunning) CurrentTrack.Stop(); } From 19023e7d437037172dee9aafc1b252af02108e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 31 Oct 2020 16:08:15 +0100 Subject: [PATCH 2/5] Fix player restart invoking user-level pause --- osu.Game/Screens/Play/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 3c0c643413..4427bb02e2 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -472,7 +472,7 @@ namespace osu.Game.Screens.Play { // at the point of restarting the track should either already be paused or the volume should be zero. // stopping here is to ensure music doesn't become audible after exiting back to PlayerLoader. - musicController.Stop(); + musicController.Stop(false); sampleRestart?.Play(); RestartRequested?.Invoke(); From 79f47953a800bcdd35951785ff266919dd39bf03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 31 Oct 2020 16:08:27 +0100 Subject: [PATCH 3/5] Migrate existing call to new flag parameter --- osu.Game/Tests/Visual/OsuTestScene.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index e32ed07863..1c9bdd43ab 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -189,7 +189,7 @@ namespace osu.Game.Tests.Visual rulesetDependencies?.Dispose(); if (MusicController?.TrackLoaded == true) - MusicController.CurrentTrack.Stop(); + MusicController.Stop(false); if (contextFactory?.IsValueCreated == true) contextFactory.Value.ResetDatabase(); From d2f6303988b24991d7b88d7cfe3613df185040da Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 2 Nov 2020 14:56:50 +0900 Subject: [PATCH 4/5] Change default value of requestedByUser to false --- osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs | 2 +- osu.Game/Overlays/MusicController.cs | 4 ++-- osu.Game/Screens/Play/Player.cs | 2 +- osu.Game/Tests/Visual/OsuTestScene.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs index c96952431a..5963f806c6 100644 --- a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs +++ b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs @@ -56,7 +56,7 @@ namespace osu.Game.Tests.Visual.Navigation AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); if (withUserPause) - AddStep("pause", () => Game.Dependencies.Get().Stop()); + AddStep("pause", () => Game.Dependencies.Get().Stop(true)); AddStep("press enter", () => pressAndRelease(Key.Enter)); diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 7e7be31de6..eafbeebbc9 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -187,7 +187,7 @@ namespace osu.Game.Overlays /// Specifying true will ensure that other methods like /// will not resume music playback until the next explicit call to . /// - public void Stop(bool requestedByUser = true) + public void Stop(bool requestedByUser = false) { IsUserPaused |= requestedByUser; if (CurrentTrack.IsRunning) @@ -201,7 +201,7 @@ namespace osu.Game.Overlays public bool TogglePause() { if (CurrentTrack.IsRunning) - Stop(); + Stop(true); else Play(); diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 4427bb02e2..3c0c643413 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -472,7 +472,7 @@ namespace osu.Game.Screens.Play { // at the point of restarting the track should either already be paused or the volume should be zero. // stopping here is to ensure music doesn't become audible after exiting back to PlayerLoader. - musicController.Stop(false); + musicController.Stop(); sampleRestart?.Play(); RestartRequested?.Invoke(); diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 1c9bdd43ab..198d22fedd 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -189,7 +189,7 @@ namespace osu.Game.Tests.Visual rulesetDependencies?.Dispose(); if (MusicController?.TrackLoaded == true) - MusicController.Stop(false); + MusicController.Stop(); if (contextFactory?.IsValueCreated == true) contextFactory.Value.ResetDatabase(); From 8f2cd0e8c55178b75315c912d1c4eeb25e1d5f08 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 2 Nov 2020 15:01:30 +0900 Subject: [PATCH 5/5] Add matching requestedByUser parameter to Play method --- osu.Game/Overlays/MusicController.cs | 13 ++++++++++--- osu.Game/Screens/Select/SongSelect.cs | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index eafbeebbc9..d78f387b30 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -166,10 +166,17 @@ namespace osu.Game.Overlays /// /// Start playing the current track (if not already playing). /// + /// Whether to restart the track from the beginning. + /// + /// Whether the request to play was issued by the user rather than internally. + /// Specifying true will ensure that other methods like + /// will resume music playback going forward. + /// /// Whether the operation was successful. - public bool Play(bool restart = false) + public bool Play(bool restart = false, bool requestedByUser = false) { - IsUserPaused = false; + if (requestedByUser) + IsUserPaused = false; if (restart) CurrentTrack.Restart(); @@ -203,7 +210,7 @@ namespace osu.Game.Overlays if (CurrentTrack.IsRunning) Stop(true); else - Play(); + Play(requestedByUser: true); return true; } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index a85e1869be..0473efd404 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -579,7 +579,8 @@ namespace osu.Game.Screens.Select updateComponentFromBeatmap(Beatmap.Value); // restart playback on returning to song select, regardless. - music.Play(); + // not sure this should be a permanent thing (we may want to leave a user pause paused even on returning) + music.Play(requestedByUser: true); } this.FadeIn(250);