From 3e770677ab66b2209c5ea0d3e973018cc0f266e8 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 6 Jun 2021 21:41:24 -0700 Subject: [PATCH] Separate out PlayerSource (nw) --- RedBookPlayer/PlayerSource.cs | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 RedBookPlayer/PlayerSource.cs diff --git a/RedBookPlayer/PlayerSource.cs b/RedBookPlayer/PlayerSource.cs new file mode 100644 index 0000000..3b73f5a --- /dev/null +++ b/RedBookPlayer/PlayerSource.cs @@ -0,0 +1,44 @@ +using System; +using CSCore; +using WaveFormat = CSCore.WaveFormat; + +namespace RedBookPlayer +{ + public class PlayerSource : IWaveSource + { + public delegate int ReadFunction(byte[] buffer, int offset, int count); + + readonly ReadFunction _read; + + public bool Run = true; + + public PlayerSource(ReadFunction read) => _read = read; + + public WaveFormat WaveFormat => new WaveFormat(); + bool IAudioSource.CanSeek => throw new NotImplementedException(); + + public long Position + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + + public long Length => throw new NotImplementedException(); + + public int Read(byte[] buffer, int offset, int count) + { + if(Run) + return _read(buffer, offset, count); + + Array.Clear(buffer, offset, count); + + return count; + } + + public void Dispose() {} + + public void Start() => Run = true; + + public void Stop() => Run = false; + } +} \ No newline at end of file