26 lines
697 B
C#
26 lines
697 B
C#
using System;
|
|
|
|
namespace FlowScope.Audio
|
|
{
|
|
public sealed class AudioHandle : IAudioHandle
|
|
{
|
|
private readonly Func<bool> _isPlaying;
|
|
private readonly Action<float> _stop;
|
|
|
|
internal AudioHandle(Func<bool> isPlaying, Action<float> stop)
|
|
{
|
|
_isPlaying = isPlaying ?? throw new ArgumentNullException(nameof(isPlaying));
|
|
_stop = stop ?? throw new ArgumentNullException(nameof(stop));
|
|
}
|
|
|
|
public bool IsPlaying => _isPlaying();
|
|
|
|
public void Stop(float fadeOut = 0f)
|
|
{
|
|
_stop(fadeOut);
|
|
}
|
|
|
|
internal static AudioHandle Stopped { get; } = new AudioHandle(() => false, _ => { });
|
|
}
|
|
}
|