mirror of
https://github.com/ppy/osu
synced 2024-12-30 19:02:27 +00:00
Allow preview tracks to exist without an owner (without hard crashing)
This commit is contained in:
parent
34f09e2e20
commit
199043f677
@ -11,6 +11,7 @@ using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Audio
|
||||
@ -76,7 +77,7 @@ namespace osu.Game.Audio
|
||||
/// <param name="source">The <see cref="IPreviewTrackOwner"/> which may be the owner of the <see cref="PreviewTrack"/>.</param>
|
||||
public void StopAnyPlaying(IPreviewTrackOwner source)
|
||||
{
|
||||
if (CurrentTrack == null || CurrentTrack.Owner != source)
|
||||
if (CurrentTrack == null || (CurrentTrack.Owner != null && CurrentTrack.Owner != source))
|
||||
return;
|
||||
|
||||
CurrentTrack.Stop();
|
||||
@ -86,11 +87,12 @@ namespace osu.Game.Audio
|
||||
/// <summary>
|
||||
/// Creates the <see cref="TrackManagerPreviewTrack"/>.
|
||||
/// </summary>
|
||||
protected virtual TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) => new TrackManagerPreviewTrack(beatmapSetInfo, trackStore);
|
||||
protected virtual TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, ITrackStore trackStore) =>
|
||||
new TrackManagerPreviewTrack(beatmapSetInfo, trackStore);
|
||||
|
||||
public class TrackManagerPreviewTrack : PreviewTrack
|
||||
{
|
||||
[Resolved]
|
||||
[Resolved(canBeNull: true)]
|
||||
public IPreviewTrackOwner Owner { get; private set; }
|
||||
|
||||
private readonly BeatmapSetInfo beatmapSetInfo;
|
||||
@ -102,6 +104,12 @@ namespace osu.Game.Audio
|
||||
this.trackManager = trackManager;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Logger.Log($"A {nameof(PreviewTrack)} was created without a containing {nameof(IPreviewTrackOwner)}. An owner should be added for correct behaviour.");
|
||||
}
|
||||
|
||||
protected override Track GetTrack() => trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user