Merge pull request #10640 from bdach/fix-music-paused-on-multi-exit

This commit is contained in:
Dean Herbert
2020-11-02 15:46:19 +09:00
committed by GitHub
4 changed files with 22 additions and 9 deletions

View File

@ -56,7 +56,7 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
if (withUserPause) if (withUserPause)
AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop()); AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop(true));
AddStep("press enter", () => pressAndRelease(Key.Enter)); AddStep("press enter", () => pressAndRelease(Key.Enter));

View File

@ -166,9 +166,16 @@ namespace osu.Game.Overlays
/// <summary> /// <summary>
/// Start playing the current track (if not already playing). /// Start playing the current track (if not already playing).
/// </summary> /// </summary>
/// <param name="restart">Whether to restart the track from the beginning.</param>
/// <param name="requestedByUser">
/// Whether the request to play was issued by the user rather than internally.
/// Specifying <c>true</c> will ensure that other methods like <see cref="EnsurePlayingSomething"/>
/// will resume music playback going forward.
/// </param>
/// <returns>Whether the operation was successful.</returns> /// <returns>Whether the operation was successful.</returns>
public bool Play(bool restart = false) public bool Play(bool restart = false, bool requestedByUser = false)
{ {
if (requestedByUser)
IsUserPaused = false; IsUserPaused = false;
if (restart) if (restart)
@ -182,9 +189,14 @@ namespace osu.Game.Overlays
/// <summary> /// <summary>
/// Stop playing the current track and pause at the current position. /// Stop playing the current track and pause at the current position.
/// </summary> /// </summary>
public void Stop() /// <param name="requestedByUser">
/// Whether the request to stop was issued by the user rather than internally.
/// Specifying <c>true</c> will ensure that other methods like <see cref="EnsurePlayingSomething"/>
/// will not resume music playback until the next explicit call to <see cref="Play"/>.
/// </param>
public void Stop(bool requestedByUser = false)
{ {
IsUserPaused = true; IsUserPaused |= requestedByUser;
if (CurrentTrack.IsRunning) if (CurrentTrack.IsRunning)
CurrentTrack.Stop(); CurrentTrack.Stop();
} }
@ -196,9 +208,9 @@ namespace osu.Game.Overlays
public bool TogglePause() public bool TogglePause()
{ {
if (CurrentTrack.IsRunning) if (CurrentTrack.IsRunning)
Stop(); Stop(true);
else else
Play(); Play(requestedByUser: true);
return true; return true;
} }

View File

@ -579,7 +579,8 @@ namespace osu.Game.Screens.Select
updateComponentFromBeatmap(Beatmap.Value); updateComponentFromBeatmap(Beatmap.Value);
// restart playback on returning to song select, regardless. // 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); this.FadeIn(250);

View File

@ -189,7 +189,7 @@ namespace osu.Game.Tests.Visual
rulesetDependencies?.Dispose(); rulesetDependencies?.Dispose();
if (MusicController?.TrackLoaded == true) if (MusicController?.TrackLoaded == true)
MusicController.CurrentTrack.Stop(); MusicController.Stop();
if (contextFactory?.IsValueCreated == true) if (contextFactory?.IsValueCreated == true)
contextFactory.Value.ResetDatabase(); contextFactory.Value.ResetDatabase();