Beispiel #1
0
        private void SetAudioStatus(AudioStatus status)
        {
            lock (Graph)
            {
                if (status != Status)
                {
                    if (status != AudioStatus.Stopped && Status != AudioStatus.Stopped)
                    {
                        throw new Exception($"Can't transition from {Status} to {status}");
                    }

                    if (status == AudioStatus.Recording)
                    {
                        InputDevice.AddOutgoingConnection(RecordingOutputNode);
                        InputDevice.Start();
                        Graph.Start();
                    }
                    else if (status == AudioStatus.Playing)
                    {
                        Graph.Start();
                    }
                    else if (status == AudioStatus.Stopped)
                    {
                        Graph.Stop();

                        if (Status == AudioStatus.Recording)
                        {
                            InputDevice.RemoveOutgoingConnection(RecordingOutputNode);
                            InputDevice.Stop();
                        }
                        else if (Status == AudioStatus.Playing)
                        {
                            InputNodes.ForEach(x =>
                            {
                                x.RemoveOutgoingConnection(OutputDevice);
                                x.Dispose();
                            });
                            InputNodes.Clear();
                        }
                    }

                    Status = status;
                    AudioStatusChanged?.Invoke(this, status);
                }
            }
        }