public void ToggleVideo(bool enableVideo, string videoDevice) { if (enableVideo && videoSource != null) { return; } if (!enableVideo && videoSource == null) { return; } if (!enableVideo) { videoSource.SignalToStop(); videoSource.NewFrame -= video_source_NewFrame; videoSource = null; var settings = ToxAv.DefaultCodecSettings; settings.CallType = ToxAvCallType.Audio; toxav.ChangeSettings(CallIndex, settings); } else { var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach (FilterInfo device in videoDevices) { if (device.Name == videoDevice) { videoSource = new VideoCaptureDevice(device.MonikerString); videoSource.NewFrame += video_source_NewFrame; videoSource.Start(); var settings = ToxAv.DefaultCodecSettings; settings.CallType = ToxAvCallType.Video; toxav.ChangeSettings(CallIndex, settings); break; } } } }