2021-10-04 21:50:44 -07:00
|
|
|
using CSCore.SoundOut;
|
|
|
|
|
|
2021-10-06 20:52:16 -07:00
|
|
|
namespace RedBookPlayer.Models.Audio.Windows
|
2021-10-04 21:50:44 -07:00
|
|
|
{
|
|
|
|
|
public class AudioBackend : IAudioBackend
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sound output instance
|
|
|
|
|
/// </summary>
|
2021-10-05 21:40:41 -07:00
|
|
|
private readonly ALSoundOut _soundOut;
|
2021-10-04 21:50:44 -07:00
|
|
|
|
|
|
|
|
public AudioBackend() { }
|
|
|
|
|
|
|
|
|
|
public AudioBackend(PlayerSource source)
|
|
|
|
|
{
|
|
|
|
|
_soundOut = new ALSoundOut(100);
|
|
|
|
|
_soundOut.Initialize(source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IAudioBackend Implementation
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void Pause() => _soundOut.Pause();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void Play() => _soundOut.Play();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void Stop() => _soundOut.Stop();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public PlayerState GetPlayerState()
|
|
|
|
|
{
|
|
|
|
|
return (_soundOut?.PlaybackState) switch
|
|
|
|
|
{
|
|
|
|
|
PlaybackState.Paused => PlayerState.Paused,
|
|
|
|
|
PlaybackState.Playing => PlayerState.Playing,
|
|
|
|
|
PlaybackState.Stopped => PlayerState.Stopped,
|
|
|
|
|
_ => PlayerState.NoDisc,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void SetVolume(float volume)
|
|
|
|
|
{
|
|
|
|
|
if (_soundOut != null)
|
|
|
|
|
_soundOut.Volume = volume;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|