예제 #1
0
        public async Task SendToStream(VoiceNextConnection voiceStream)
        {
            try
            {
                var sink           = voiceStream.GetTransmitSink(_soundSettings.SampleSize);
                var bytesPerSample = _remoteBuffer.BytesPerSample(sink.SampleDuration);
                streamBuffer = new byte[bytesPerSample];

                await Task.Delay(_soundSettings.BufferDurationMs);

                while (_playing)
                {
                    if (_remoteBuffer.BufferedBytes >= bytesPerSample)
                    {
                        _remoteBuffer.Read(streamBuffer, 0, bytesPerSample);
                        await sink.WriteAsync(streamBuffer, 0, bytesPerSample);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e, $"An error occured during transmission to stream: {e.Message}");
                Stop();
            }
        }