mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Allow preview tracks to exist without an owner (without hard crashing)
This commit is contained in:
@ -11,6 +11,7 @@ using osu.Framework.Audio.Track;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
|
||||||
namespace osu.Game.Audio
|
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>
|
/// <param name="source">The <see cref="IPreviewTrackOwner"/> which may be the owner of the <see cref="PreviewTrack"/>.</param>
|
||||||
public void StopAnyPlaying(IPreviewTrackOwner source)
|
public void StopAnyPlaying(IPreviewTrackOwner source)
|
||||||
{
|
{
|
||||||
if (CurrentTrack == null || CurrentTrack.Owner != source)
|
if (CurrentTrack == null || (CurrentTrack.Owner != null && CurrentTrack.Owner != source))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CurrentTrack.Stop();
|
CurrentTrack.Stop();
|
||||||
@ -86,11 +87,12 @@ namespace osu.Game.Audio
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the <see cref="TrackManagerPreviewTrack"/>.
|
/// Creates the <see cref="TrackManagerPreviewTrack"/>.
|
||||||
/// </summary>
|
/// </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
|
public class TrackManagerPreviewTrack : PreviewTrack
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved(canBeNull: true)]
|
||||||
public IPreviewTrackOwner Owner { get; private set; }
|
public IPreviewTrackOwner Owner { get; private set; }
|
||||||
|
|
||||||
private readonly BeatmapSetInfo beatmapSetInfo;
|
private readonly BeatmapSetInfo beatmapSetInfo;
|
||||||
@ -102,6 +104,12 @@ namespace osu.Game.Audio
|
|||||||
this.trackManager = trackManager;
|
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");
|
protected override Track GetTrack() => trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user