//-------------------------------------------------------------------------------------------------------- public MainViewModel() { RecordCollection = new CollectionRecord(); this.visualizations = new SpectrumAnalyzerVisualization(); this.AudioPlayBack = new AudioPlayBack(); AudioPlayBack.MaximumCalculated += audioGraph_MaximumCalculated; AudioPlayBack.FftCalculated += audioGraph_FftCalculated; var enumerator = new MMDeviceEnumerator(); CaptureDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToArray(); var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); SelectedDevice = CaptureDevices.FirstOrDefault(c => c.ID == defaultDevice.ID); synchronizationContext = SynchronizationContext.Current; this.OpenFileCommand = new RelayCommand(this.OpenFolderAndLoadSound); this.PlayCommand = new RelayCommand(this.Play); this.StopCommand = new RelayCommand(this.Stop); this.NextSound = new RelayCommand(this.NextTrack); this.PreviousSound = new RelayCommand(this.PreviosTrack); this.StartRecordCommand = new RelayCommand(this.Record); this.StopRecordCommand = new RelayCommand(this.StopRecord); this.CloseWindowCommand = new RelayCommand(this.CloseWindow); //--------------------------------------------------------------- timer.Interval = TimeSpan.FromMilliseconds(900); //Интервал вызова - Обновлять позицию каждые 900 миллисекунд timer.Tick += TimerOnTick; //Привязка метода к таймеру }
public AudioCaptureSettingsViewModel() { CaptureProviders = Modules.Capture; IAudioCaptureProvider savedCaptureProvider = Modules.Capture.FirstOrDefault(p => p.GetType().GetSimpleName() == Settings.VoiceProvider); if (savedCaptureProvider == null) { CurrentCaptureProvider = Modules.Capture.FirstOrDefault(); } else { CurrentCaptureProvider = savedCaptureProvider; if (Settings.VoiceDevice != null) { var setDevice = CaptureDevices.FirstOrDefault(d => d.Device.Name == Settings.VoiceDevice); if (setDevice != null) { CurrentCaptureDevice = setDevice; } } } VoiceActivationThreshold = Settings.VoiceActivationLevel; VoiceActivationSilenceThreshold = Settings.VoiceActivationContinueThreshold / 100; UseVoiceActivation = !Settings.UsePushToTalk; }
private void TryInitializeDevices() { var enumerator = new MMDeviceEnumerator(); CaptureDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToArray(); IsAnyDevice = CaptureDevices.Any(); var defaultDevice = TryGetDevice(enumerator); SelectedDevice = CaptureDevices.FirstOrDefault(c => c.ID == defaultDevice?.ID); }
public void RemoveCaptureDevice(Item item, int count = 1) { if (CaptureDevices[item] < count) { return; } CaptureDevices[item] -= count; if (CaptureDevices[item] == 0) { CaptureDevices.Remove(item); } }
public Form1() { wi = new WaveIn(WaveCallbackInfo.FunctionCallback());//初始化WaveIn对象 wi.DataAvailable += new EventHandler <WaveInEventArgs>(wi_DataAvailable); InitializeComponent(); //第二步 MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); //第三步 CaptureDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToArray(); //MMDevice defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); //第四步 selectedDevice = CaptureDevices.FirstOrDefault(); //c => c.ID == defaultDevice.ID }
public WasapiCaptureViewModel() { synchronizationContext = SynchronizationContext.Current; var enumerator = new MMDeviceEnumerator(); CaptureDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToArray(); var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); SelectedDevice = CaptureDevices.FirstOrDefault(c => c.ID == defaultDevice.ID); RecordCommand = new DelegateCommand(Record); StopCommand = new DelegateCommand(Stop) { IsEnabled = false }; RecordingsViewModel = new RecordingsViewModel(); }
public MainWindowViewModel() { Title = "Photomaton"; IsFullScreen = true; CaptureCommand = new DelegateCommand(Capture, CanCapture); ToggleFullScreenCommand = new DelegateCommand(ToggleFullScreen, CanToggleFullScreen); ToggleStretchCommand = new DelegateCommand <StretchModes>(ToggleStretch, CanToggleStretch); OpenStretchOptionsCommand = new DelegateCommand(OpenStretchOptions, CanOpenStretchOptions); OpenSettingsCommand = new DelegateCommand(OpenSettings, CanOpenSettings); ChangeDeviceCommand = new DelegateCommand <DsDevice>(ChangeDevice, CanChangeDevice); if (!Directory.Exists(ImgFolder)) { Directory.CreateDirectory(ImgFolder); } RefreshDevicesList(); CaptureDevice = CaptureDevices.FirstOrDefault(); }