osu/osu.Game/Audio/PreviewTrack.cs

54 lines
1.5 KiB
C#
Raw Normal View History

2018-05-24 21:37:53 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
2018-05-24 21:37:53 +00:00
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
2018-06-01 18:06:37 +00:00
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
2018-05-24 21:37:53 +00:00
namespace osu.Game.Audio
{
public class PreviewTrack : Component
2018-05-24 21:37:53 +00:00
{
public Track Track { get; private set; }
2018-06-02 19:06:45 +00:00
private readonly OverlayContainer owner;
2018-06-01 18:06:37 +00:00
private readonly BeatmapSetInfo beatmapSetInfo;
2018-05-24 21:37:53 +00:00
public event Action Stopped;
public event Action Started;
public PreviewTrack(BeatmapSetInfo beatmapSetInfo, OverlayContainer owner)
2018-05-24 21:37:53 +00:00
{
this.beatmapSetInfo = beatmapSetInfo;
2018-06-02 19:06:45 +00:00
this.owner = owner;
2018-05-24 21:37:53 +00:00
}
[BackgroundDependencyLoader]
private void load(PreviewTrackManager previewTrackManager)
{
Track = previewTrackManager.Get(this, beatmapSetInfo);
}
2018-05-24 21:37:53 +00:00
public void Start()
{
Track.Restart();
Started?.Invoke();
}
2018-06-02 19:06:45 +00:00
/// <summary>
/// Stop preview playback
/// </summary>
/// <param name="source">An <see cref="OverlayContainer"/> which is probably the owner of this <see cref="PreviewTrack"/></param>
public void Stop(OverlayContainer source = null)
2018-05-24 21:37:53 +00:00
{
2018-06-02 19:06:45 +00:00
if (source != null && owner != source)
return;
2018-05-24 21:37:53 +00:00
Track.Stop();
Stopped?.Invoke();
}
}
}